Possible Duplicate:
Meaning of “const” last in a C++ method declaration?
In the below function declaration,
const char* c_str ( ) const;
what does the second const do ?
It means the method is a "const method" A call to such a method cannot change any of the instance's data (with the exception of mutable data members) and can only call other const methods.
Const methods can be called on const or non-const instances, but non-const methods can only be called on non-const instances.
struct Foo {
void bar() const {}
void boo() {}
};
Foo f0;
f0.bar(); // OK
fo.boo(); // OK
const Foo f1;
f1.bar(); // OK
f1.boo(); // Error!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With