enum problems with C++
-
I've been using C# for the last few years but now I have to work with an embedded C++ compiler and am having problems with enum types, since they can't apparently be used in a different class.
class Message { public: enum Index { Length,ID1,ID2,ID3,Type,From,To,SourceX,SourceY,Var,Routing,MaxIndex=255 }; .... .... .... } ... ... ... bool Sensor::SendMessage(Message msg) { char message[Message.MaxIndex]; message[Message.ID1] = 'X'; ... ... }
This sort of thing works fine in C# but the C++ compiler gives an error when 'Message.MaxIndex' etc is used - it says 'type names cannot be used' (or similar depending on the compiler). Do I really have to make all my enum's global (e.g. 'Message_MaxIndex') or is there a better way? -
I've been using C# for the last few years but now I have to work with an embedded C++ compiler and am having problems with enum types, since they can't apparently be used in a different class.
class Message { public: enum Index { Length,ID1,ID2,ID3,Type,From,To,SourceX,SourceY,Var,Routing,MaxIndex=255 }; .... .... .... } ... ... ... bool Sensor::SendMessage(Message msg) { char message[Message.MaxIndex]; message[Message.ID1] = 'X'; ... ... }
This sort of thing works fine in C# but the C++ compiler gives an error when 'Message.MaxIndex' etc is used - it says 'type names cannot be used' (or similar depending on the compiler). Do I really have to make all my enum's global (e.g. 'Message_MaxIndex') or is there a better way?Try Message::ID1. In C++ scope resolution operator is ::. -Saurabh