how to fix error C2993: 'float' : illegal type for non-type template parameter '
-
Hi, I am porting a VC6.0 code to VS2008. I have a class with following decalration template type lowerBound, type upperBound> class TempClass { public: TempClass(void ); //virtual ~TempClass(void); protected: type mValue; }; template TempClass<type,>::TempClass(void) { // TBI } I am declaring a pointer to this class as TempClass <float, 1,2> *pT1; I am getting the error error C2993: 'float' : illegal type for non-type template parameter 'lowerBound' error C2993: 'float' : illegal type for non-type template parameter 'upperBound' how can I fix this problem? I cannot use the pointers for lowerBound, upperBound.
-
Hi, I am porting a VC6.0 code to VS2008. I have a class with following decalration template type lowerBound, type upperBound> class TempClass { public: TempClass(void ); //virtual ~TempClass(void); protected: type mValue; }; template TempClass<type,>::TempClass(void) { // TBI } I am declaring a pointer to this class as TempClass <float, 1,2> *pT1; I am getting the error error C2993: 'float' : illegal type for non-type template parameter 'lowerBound' error C2993: 'float' : illegal type for non-type template parameter 'upperBound' how can I fix this problem? I cannot use the pointers for lowerBound, upperBound.
Directly? You can't - C++ requires integral types for non-type template parameters. How about supplying the parameters as ints and casting to the required type in the class, like this?
template<class Type, int LowerBound, int HigherBound>
class TempClass { ... };Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
Hi, I am porting a VC6.0 code to VS2008. I have a class with following decalration template type lowerBound, type upperBound> class TempClass { public: TempClass(void ); //virtual ~TempClass(void); protected: type mValue; }; template TempClass<type,>::TempClass(void) { // TBI } I am declaring a pointer to this class as TempClass <float, 1,2> *pT1; I am getting the error error C2993: 'float' : illegal type for non-type template parameter 'lowerBound' error C2993: 'float' : illegal type for non-type template parameter 'upperBound' how can I fix this problem? I cannot use the pointers for lowerBound, upperBound.
template<class lowerBoundType, class upperBoundType>
Class TempClass
{
…
};OR
template<typename lowerBoundType, typename upperBoundType>
Class TempClass
{
…
};Reasonable Declarations:
TempClass<float, float>* pT1.
TempClass<double, double>* pT1.
TempClass<int, int>* pT1.If both upper and lower bounds use the same type, which would make since, then a more reasonable template would be:
template<typename boundryType>
Class TempClass
{
…
};Declaration:
TempClass<float>* pT1.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra