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 - Extract Text from HTTP referer -

Receive udp packets in android gstreamer -

authentication - ASP.NET Core 1.0. Bearer Token, cannot access custom claims -