Consider the following class:
class ConstTest
{
public:
ConstTest() : myPrivateData(42) {}
const int* getMyPrivateData() const {std::cout << "const" << std::endl; return &myPrivateData;}
int* getMyPrivateData() {std::cout << "non-const" << std::endl; return &myPrivateData;}
private:
int myPrivateData;
};
is there any rule in which context which getter is used. My impression is that only in a const environemtn the const getter is called. Can anyone confirm this? I would very much appreciate an offical source because I would like to rely on that feature.
EDIT:
I am aware I can try it. But can I rely on it in terms of the standard?