Jump to content
  • Advertisement
Sign in to follow this  
Bob Janova

Noob question: const in C++

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

So yeah, can someone please tell me what const means in method declarations, i.e. what the difference is between void foo(Thing& bar) and void foo(const Thing& bar) ... and betweeen Thing& goo() and const Thing& goo() Thank you :). (When I have time I will learn C++ from the ground up properly, but right now I don't so I have to ask stupid questions like this.)

Share this post


Link to post
Share on other sites
Advertisement
Quote:
so I have to ask stupid questions like this

do you? couldn't you try a search?
http://www.parashift.com/c++-faq-lite/const-correctness.html

Share this post


Link to post
Share on other sites
http://www.parashift.com/c++-faq-lite/const-correctness.html linkified.

void foo(Thing& bar) takes a reference to a Thing, and thus can modify it.
void foo(const Thing& bar) takes a const reference, and thus foo is not able to modify bar.
Thing& goo() returns a reference to a thing, and such reference can be modified by the caller
const Thing& goo() returns a constant reference that can't be modified by the caller.

HTH,

Share this post


Link to post
Share on other sites
Thanks, Emmanuel.

Yes, of course I could have searched, however the 'distilled intelligence' answers one can get on Gamedev are more helpful than wading through the Internet to work it out.

Share this post


Link to post
Share on other sites
1) No they're not. Not always. You can dig up a lot of misinformation here as well.
2) Learning to find the information you need online is a major part of learning programming.
3) Have you considered that the "distilled intelligence" here might prefer if people look up the trivial questions themselves, so it can focus on the difficult ones, the ones that aren't easily answered?

What you're saying is, you prefer to waste other people's time instead of yours?

Ok, that sounds harsh, but isn't that what it boils down to? You'd rather waste someone else's time by asking them questions because they're friendly enough to answer, than spend a minute of your own time with Google? [wink]

Share this post


Link to post
Share on other sites
ouch ...

I just want to say I think you should research on your own first, ALWAYS! and then come here and ask your remaining questions and clairifications. In this way you get the best of both worlds. Gamedev doesn't get bogged down responding with the top links from google (since that's what google is for) and people who don't know enough about a topic to properly search on google, or who don't have the proper background to understand the results they find can come to gamedev and get answers.

Share this post


Link to post
Share on other sites
Quote:
Original post by Bob Janova
Okay, well I apologise. Next time I'll search first. Thanks for the link to the FAQ as well!


How ironic, I get voted down for saying what I did and then you thank me and take my advice lmao.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!