problem in porting template class from VS6.0 to VS2008
-
I have a class which is using the float as template parameter . The code compiles correctly in VC6.0. But in VS2008 float is not allowed as template paramemter. So i am using the float pointer(please let me know if there is any alternative other than using int as data type). when I compile the code I get following errors at multiple places syntax error : missing ',' before identifier 'lowerBound' syntax error : missing ',' before identifier 'upperBound' 'tBoundedType' : too many template arguments How can fix this? what is error in this class declaration here is my float pointer class declaration #ifndef tBoundedType_h #define tBoundedType_h #define CLASSID_TBOUNDEDTYPE 27 template class tBoundedType { public: tBoundedType(); // Sets the value to lowerBound. tBoundedType(float * value); // An Ensure fails if value is not between lowerBound and upperBound. // tBoundedType & operator=(float *); // An Ensure fails if value is not between lowerBound and upperBound. static float LowerBound() { return lowerBound; } static float UpperBound() { return upperBound; } // operator type() const { return mValue; } // Stream me //virtual void PerformIO(tNSStream *); virtual long GetClassId() const { return CLASSID_TBOUNDEDTYPE; } long GetVersion() const { return 1; } protected: float mValue; }; template tBoundedType<lowerbound,>::tBoundedType() : mValue(*lowerBound) { } template tBoundedType::tBoundedType(float * newValue) : mValue(*newValue) { Ensure(mValue >= *lowerBound); Ensure(mValue <= *upperBound); } template tBoundedType & tBoundedType::operator=(type newValue) { Ensure(newValue >= lowerBound); Ensure(newValue <= upperBound); mValue = *newValue; return *this; } template void tBoundedType::PerformIO( tNSStream *stream ) { //int version = GetVersion(); //stream->DoIO( version ); //stream->DoIO( mValue ); }
-
I have a class which is using the float as template parameter . The code compiles correctly in VC6.0. But in VS2008 float is not allowed as template paramemter. So i am using the float pointer(please let me know if there is any alternative other than using int as data type). when I compile the code I get following errors at multiple places syntax error : missing ',' before identifier 'lowerBound' syntax error : missing ',' before identifier 'upperBound' 'tBoundedType' : too many template arguments How can fix this? what is error in this class declaration here is my float pointer class declaration #ifndef tBoundedType_h #define tBoundedType_h #define CLASSID_TBOUNDEDTYPE 27 template class tBoundedType { public: tBoundedType(); // Sets the value to lowerBound. tBoundedType(float * value); // An Ensure fails if value is not between lowerBound and upperBound. // tBoundedType & operator=(float *); // An Ensure fails if value is not between lowerBound and upperBound. static float LowerBound() { return lowerBound; } static float UpperBound() { return upperBound; } // operator type() const { return mValue; } // Stream me //virtual void PerformIO(tNSStream *); virtual long GetClassId() const { return CLASSID_TBOUNDEDTYPE; } long GetVersion() const { return 1; } protected: float mValue; }; template tBoundedType<lowerbound,>::tBoundedType() : mValue(*lowerBound) { } template tBoundedType::tBoundedType(float * newValue) : mValue(*newValue) { Ensure(mValue >= *lowerBound); Ensure(mValue <= *upperBound); } template tBoundedType & tBoundedType::operator=(type newValue) { Ensure(newValue >= lowerBound); Ensure(newValue <= upperBound); mValue = *newValue; return *this; } template void tBoundedType::PerformIO( tNSStream *stream ) { //int version = GetVersion(); //stream->DoIO( version ); //stream->DoIO( mValue ); }
When you post code, please tick the "Auto-encode HTML when pasting?" check-box. Doing that escapes the < sign, making your template code readable - which it really isn't now.
Hemant kulkarni wrote:
please let me know if there is any alternative other than using int as data type
C++ templates only allow types and integral constant values as template parameters - so, no alternative, really...unless you encode the floating point values as integral values. Repost your code with the "Auto-encode HTML when pasting?" checkbox ticked and we may be able to help you with your problem.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p