Archived

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

Kranar

Static Members in C++

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::add.setPrecedence(1);
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 this post


Link to post
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

Share this post


Link to post
Share on other sites