class A {
int num;
A* foo() const {returnconst_cast<A*>(this);}
};
The latter is more const correct of course, but is also messier in code (perhaps less efficient too?). Should we do this in general to make functions more const correct? Same goes with making pointer parameters const and such? Throwing const_cast here and there?
1 2 3 4 5 6
class A {
int num;
std::list<A*> a_list;
A* foo() const {returnconst_cast<A*>(this);}
void goo (const A* a) {a_list.push_back (const_cast<A*>(a));}
};