Jump to content
  • Advertisement

Archived

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

Kranar

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.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!