I have no solution for the real problem. I can just say do not use const_cast unless the intent calls the const member function from the non-const member function, and const_cast is the result of const (to make it a mutable result for the non-const member function).
But I have a suggestion to improve your design:
class A { private: static int v; public: A() { ++v; } static int get_v() { return v; } }; int A::v = 0; int main(int argc, char * argv[]) { A a, b, c; std::cout << a.get_v() << std::endl; return 0; }
Flinsch
source share