Topic: Enum as template parameter
Author: Xavier Huet <xavier.huet@NO_SPAM.sophia.siemens-scg.com>
Date: 1998/07/23 Raw View
Hi all,
I have a question regarding enum as template paramater.
Here is my example :
enum MY_ENUM { ZERO=0, ONE, TWO };
template <MY_ENUM e>
class MyTmpClass
{
public :
MY_ENUM GetMyEnum() const;
};
template <MY_ENUM e>
MY_ENUM
MyTmpClass<e>::GetMyEnum() const
{
return (MY_ENUM)e; //Cast needed by my compiler
}
// Main Routine
int
main(int , char** )
{
{
MyTmpClass<ZERO> zero;
cout << "zero.GetMyEnum() : " << zero.GetMyEnum() << endl;
MyTmpClass<ONE> one;
cout << "one.GetMyEnum() : " << one.GetMyEnum() << endl;
MyTmpClass<TWO> two;
cout << "two.GetMyEnum() : " << two.GetMyEnum() << endl;
MyTmpClass<3> three;
cout << "three.GetMyEnum() : " << three.GetMyEnum() << endl;
}
Is this code correct ? It compiles with SunPro 4.2 but I am surprised
about the declarations of three : MyTmpClass<3>. Since 3 is not in
MY_ENUM why does it compiles without any warnings ?
Thank in advance
~Xavier
[ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
[ about comp.lang.c++.moderated. First time posters: do this! ]