Public Group

Archived

This topic is now archived and is closed to further replies.

Static Members in C++

This topic is 5268 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I have an Operator class I''m working on, basically every Operator stores the symbol used to invoke it, a precedence level, and the number of operands that it takes. I want to define some global Operators like add, sub, div, mul. Thing is I don''t know where to assign them their properties. I have this so far..
class Operator {
public:
...
some stuff
...
static Operator nothing, add, sub, mul, div,
and, or, assign, inc, dec, eq, neq;
};

Operator::sub.setPrecedence(2);

Thing is I keep getting compiler errors: Operator.cpp(16): error C2143: syntax error : missing '';'' before ''.'' Anyone know what''s wrong? Thanks.

Share on other sites
You''d have to put your code to do that somewhere. You can''t just stick code in the main body of your program, it has to be in some kind of function.

One option is to send a parameter to the constructor of your class to do it, then you won''t need to.

Mark

1. 1
2. 2
Rutin
18
3. 3
4. 4
5. 5
frob
12

• 9
• 21
• 11
• 9
• 17
• Forum Statistics

• Total Topics
632606
• Total Posts
3007383

×