Derived template class constexpr constructor

312 views Asked by At

I am trying to derive class with constexpr constructor from template class, which has constexpr constructor to. Derived class defines only constructor. I got this error...

main.h

template <class T>
class ExprTemplate
{
public:
const T a;
constexpr ExprTemplate (const T in):a(in){}
constexpr T GetA() const {return a;}
};

class DelivExpr : public ExprTemplate<int>
{
    public:
        constexpr DelivExpr(const int in): ExprTemplate<int> (in){}

};

template <int n>
struct constN
{
    constN() {i = n;}
        uint32_t i;
};


main.cpp

int main()
{
    constN  <   1                               >       e0;//OK
    constN  <   (ExprTemplate<int>(0)).GetA()   >       e1;//OK

    constN  <   (DelivExpr(0)).GetA()           >       e2;
//error, function call must have a constant value in a constant expression

    constexpr DelivExpr deliv(0);
    constN  <   deliv.GetA()                    >       e3;//OK!!!
}

Can anyone help please?)

0

There are 0 answers