Reputation: 353
My classes' struct needs to be one of five values. Right now it looks like this:
// Bar.h
struct Foo{
string value;
}
class Bar{
Bar();
}
// Bar.cpp
Bar::Bar(//magic here){
// or here
}
I want to set Foo to one of five values/strings as it is now (VALUEA, VALUEB,...) in the constructor, and only those five should be allowed. Its not important if the type is a string or a bool, since I just do checks on Foo if it its value == x.
How can I force the programmer to use one of the types?
Upvotes: 0
Views: 103
Reputation: 27538
Use an enum class
, not a struct
.
enum class Foo {
ValueA,
ValueB,
ValueC,
ValueD,
ValueE
};
Upvotes: 5