class A { void koo(){} void foo() const {this->koo();} }; int main() { A a; a.foo(); } I tried to call a non-const function inside const function.
error: passing ‘const A’ as ‘this’ argument of ‘void A::koo()’ discards qualifiers [-fpermissive] - What is the meaning of this error?
- Can I use mutable keyword for this, If that, how? (as this post)
- Can I use const_cast for this. If that, how? (as this post)
- Are there ant other way to do this?
const. Nope. Yes - but hacky (const_cast<A*>(this)->koo()). Yes, makekoo()constand any state it operates onmutable.koo()?const_castwill lead to undefined behaviour ifkooreally mutates the object.