What does each Const in a member function defintion mean

First in C we have
 
const int my_func() {return 0;};

This Tells the compiler that all calls to my_func() will return the same value

In C++ we have:
1
2
3
class class_name {
	const int my_member_func() const {return 0;}
};


What does the first Const and second const mean?

Thank you!
The second const tells the compiler that the function won't change member variables (there's an exception re mutable). This means that an instantiation of the class marked as const can still use const marked member functions.
Does this lead to performance optimizations from the compiler, or is this a correctness/self documentation exclusive feature?
It's mainly a correctness feature. If a class instantiated variable is marked as const, you wouldn't expect its contents to be changed - would you. The compiler will issue an error if this is tried with a member function not marked as const.

Topic archived. No new replies allowed.