Possible Duplicate:
Invoking a nonconst method on a member from a const method
Constant member functions are able to call non constant member functions via pointer member variables in C++, is it as expected? Below give code snippet is compiling successfully
#include <iostream>
class S {
public:
void hi() {
std::cout << "Hi" << std::endl;
}
};
class T {
public:
T()
: s(new S())
{}
~T()
{
delete s;
}
void hi() const {
s->hi();
}
private:
S * s;
};
int main(int argc, char ** argv) {
T t;
t.hi();
return 0;
}