c++ - `public` access qualifier and `const`ness. `-Wuninitialized` -
class foo { public: const int x; }; class bar { private: const int x; };
output:
test.cpp:10:13: warning: non-static const member ‘const int bar::x’ in class without constructor [-wuninitialized]
why bar
produce warning foo
doesn't (obviously because of access qualifier, logic?).
with definitions, since foo::x
public, can validly instantiate foo
like:
foo f { 0 }; // c++11
or
foo f = { 0 };
you can't bar
.
Comments
Post a Comment