Jump to content
  • Advertisement

Archived

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

c0nfUzEd

Making this const

This topic is 6193 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

  
class vector {
public:
   double x, y, z;
   double length ();
};

.
.
.

void dostuff (const vector f) {
   double l = f.length ();
}
  
I have some code like this, which the compiler refuses to compile, because f is supposed to be const. How do I tell the compiler that the "this" argument to vector::length () is a const?

Share this post


Link to post
Share on other sites
Advertisement
c0nfUzEd

Do you need that f to be const? Why?


_________________________
Hal - Atena Developer
www.grupoatena.hpg.com.br



Edited by - _Hal_ on December 28, 2001 5:33:35 AM

Share this post


Link to post
Share on other sites
It''s not absolutely necessary, but I dont change f in the function so it''s nice to be able to see that straight away.

Also I have inline functions that pass by reference, and I like to make them const if I can to help the compiler do its optimisations.

Share this post


Link to post
Share on other sites
FYI, your doStuff function is creating a copy of your vector. I would suggest passing-in the vector by reference:
void dostuff (const vector &f)

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!