Jump to content
  • Advertisement

Archived

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

CaffieneFreak

CONSTantly looking.

This topic is 5545 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've been looking around in every book I have, on other websites, everywhere, for information on the following. What is the difference between the following definitions: void aClass::aFunction(); and void aClass::aFunction() const; Any ideas? To be, or not to be, those are the parameters. ----------------------------------------------------- To be, or not to be, those are the parameters. [edited by - CaffieneFreak on August 16, 2003 11:50:51 PM]

Share this post


Link to post
Share on other sites
Advertisement
''const'' is used like that to declare member functions which don''t change the state of any of the class'' member variables. For example, accessor functions are almost always const(or should be.) Its good to use when you don''t change member variables; It describes your interface better and maybe leads to quicker compiled code.

Ravyne, NYN Interactive Entertainment
[My Site][My School][My Group]

Share this post


Link to post
Share on other sites
Cool, thank you. Its fairly obvious now I know the answer



-----------------------------------------------------

To be, or not to be, those are the parameters.

Share this post


Link to post
Share on other sites
Also, if you have a const object and invoke that method, the const flavor will be invoked.

e.g.


T& operator[](int i) {return vec[i];
const T& operator[](int i) const {return vec[i];}


That way with a const vector, you can still index the array, but can''t change it.

Share this post


Link to post
Share on other sites
quote:
Original post by Magmai Kai Holmlor
Also, if you have a const object and invoke that method, the const flavor will be invoked.

e.g.


T& operator[](int i) {return vec[i];
const T& operator[](int i) const {return vec[i];}


That way with a const vector, you can still index the array, but can''t change it.

Neat trick. Thanks.

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!