What's the difference between having a const function and declaring const after the function? For example, if I had a class Myclass with some private data members and I set up a public function called int getMyValue(), what would the difference be between declaring that function as:

const int getMyValue();


int getMyValue() const;

The first example associates the const-ness with the value returned from the call. In the second example you are specifying that the call can not modify the object being invoked.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.