Can i not declare a non-static const data member?
problem is here is, compiler allows me to declare a non-static const data member, meaning i can somehow use it. But how do i initialize it?Code:class A { public: const int x; A() { x = 10; } }; int main() { return 0; }
Constructor Initialization fails bcoz compiler prevents assignment to a const data member,
and initialization at declaration is prevented by ISO C++ std. that says i cannot initialize data members inside a class until they are static const
so, why even the declaration of non-static const data member has been allowed by the compiler, when there is no way i can initialize it ?