I have an enum:
enum myenum{
typeA,
typeB,
typeC
} myenum_t;
Then, a functions is to be called with an enum parameter:
Enumerations in C++ already have stronger types than in C.
Take the following simple program:
#include
enum E
{
A,
B
};
void f(E e)
{
}
int main()
{
f(1);
}
Using the GCC compiler I will get a this error:
enum.cpp: In function ‘int main()’: enum.cpp:15: error: invalid conversion from ‘int’ to ‘E’ enum.cpp:15: error: initializing argument 1 of ‘void f(E)’
So as you can see the enumeration members are already checked.
If you want even stronger type checking, and have a C++11 capable compiler, you can use even stronger type checking for enums, see http://en.wikipedia.org/wiki/C%2B%2B11#Strongly_typed_enumerations.