I’m trying to compile the following code under VC2010.
struct CircValRange
{
double a,b; // range: [a,b)
};
template <struct CircValRange* Range>
class CircVal
{
// todo
};
const CircValRange SignedDegRange= {-180., 180.};
CircVal<SignedDegRange> x;
I’m getting
error C2970: 'CircVal' : template parameter 'Range' : 'SignedDegRange' : an expression involving objects with internal linkage cannot be used as a non-type argument
1> d:\4\circval\circval\circval.h(8) : see declaration of 'CircVal'
1> d:\4\circval\circval\circval.h(13) : see declaration of 'SignedDegRange'
I am trying to define a templated class CircVal that will receive a struct Range as the templated parameter.
I don’t want it to be possible to assign classes with one range to classes with another range (I want them to be different types).
How can I do it?
Someone has recommended a constructor parameter, which I second. But you can still do it as originally desired
But notice that the property that determines the type-identity of
CircVal<SignedDegRange>is not the value ofSignedDegRange, but the address/identity of it. That is, the following does not work becauseCircVal<SignedDegRange1>denotes a different typeAs such, an enumeration may be better suited for this
Or even a traits class with static member functions, similar to a solution someone else had