C++ const nightmare

10/18/2011 16:14 Demon-777#1
Hello eveyone,

could someone of C++ profs. out here explain me following method declaration? Just got a bit confused :)

Code:
const int* const SampleMethod(const int* const&) const;
Best regards!

Demon-777
10/18/2011 16:40 ms​#2
That declaration doesn't seem to make any sense to me.

Code:
const int* const SampleMethod(const int*);
This would be a function taking a pointer to a const int as argument and returning a const int-pointer to a const int.


Edit:
Code:
const int* const SampleMethod(const int* const&);
I'm not sure, but I think this is the same as above with the argument being a reference to a const pointer to a const int. My compiler doesn't accept the declaration with your trailing const though.

Edit 2:
The trailing const in your declaration makes sense when it's a method of a class. It means that the method is not allowed to alter any members of its class.
10/18/2011 16:52 Demon-777#3
Quote:
Originally Posted by Metin2Spieler97 View Post
This would be a function taking a pointer to a const int as argument and returning a const int-pointer to a const int.
oh now I see! It's not for compilation purposes. Just learning how to use this const stuff and trying to understand all this magic C++ thingy! :)

Thank you through!

PS. got it from [Only registered and activated users can see links. Click Here To Register...], just scroll to the bottom where you'll see "Messier Still - in the Object Oriented Programming" :P That make me confused. :)