Click here to Skip to main content
15,897,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I know the question seems vague, so here's the code :

VectF Class:

C++
template <typename Type, int Size = 0>
class VectF : public Vect<Type>{
private:
    //

protected:
    static const std::size_t _DIM = Size;
    Type _values[_DIM];

public:

    // getters
    virtual std::size_t size() const {return _DIM;};
   
};


And the ModPol Class:

C++
template <typename Type, const ConPol<Type>& Div>
class ModPol : public Pol<Type>, public VectF<Type, Div.size()>{
private:
    //

protected:
    //

public:
    // constructors & destructor
    ModPol();      
    virtual ~ModPol();

};


So as you see the ModPol template class inherits from two other templates. In one of those I would like to use the result of the .size() method on Div as a parameter. Unfortunately I get this error:


Quote:
on-type template argument of type
'std::size_t' (aka 'unsigned long') is not an integral constant
expression
...: public Pol<type>, public VectF<type,>{ //


Would someone know how to get around that error ? (Do not hesitate to answer with simple words as I think of myself as a beginner).

Cheers !
Posted
Comments
Richard MacCutchan 14-Nov-15 13:12pm    
Div.size() is a class method, so its value cannot be computed by the compiler.
Member 12137831 14-Nov-15 14:24pm    
Is there any possibility to retrieve the _DIM attribute without calling a method (or making it public) ?
Richard MacCutchan 14-Nov-15 14:46pm    
No, because it does not exist at compile time.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900