The following code compiles:
class myClass
{
public:
static const int MAX = 1024; int x[MAX];
};
const int myClass::MAX;
class myClass
{
public:
enum {MAX = 1024};
int x[MAX];
};
The last class is called the enum hack, because for a while many compilers did not handle the previous class declaration.
Subscribe to:
Post Comments (Atom)
"enum hack" has one real advantage: the value can be overriden in derived class. I.e. base class value is kind of default for all derived classes until is redefined on the way.
ReplyDeleteI have a question :
ReplyDeleteconst int myClass::MAX;
Is this necessary?
I am not some experienced
This comment has been removed by the author.
ReplyDelete