Sign in to follow this  
lord4n

What is the best way to increase more than one var in a class?

Recommended Posts

The subject is my question i tried to do it like that http://rafb.net/paste/results/r5oCEj28.html is there any better way to do it when the class have like 10-11 vars that i need to increase ?

Share this post


Link to post
Share on other sites
This is the best way, yes.

However, ask yourself the question: is this the best way to represent the semantics intended for my class ? Does it make conceptual sense to have a class with 11 variables instead of a vector of size 11 ? Does it really need 11 variables ?

Or, in short: tell us more about what state you want to represent, and what incrementing this state means, and we might be able to come up with a class representation that is more elegant and compact than your approach.

Share this post


Link to post
Share on other sites
No, the way you're doing it is the best way. You could do it with horrible, horrible pointer hackery, if you know that all the integers are stored in the class consecutively, but that'll be hard to read and be an absolute nightmare to debug when things go wrong.

Offtopic:
Please use the [ source ] tags when posting code, rather than linking to another site. That way the code stays here, whereas it might be deleted from other sites, and it saves people going and looking at other sites to view the code.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this