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 barproduce 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

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -