Class visibility in C++

visibility.cpp

class S
{
    public: static int m1;
    protected: static int m2;
    private: static int m3;
    inline void doSomething1()
    {
        ++S::m1; // good
        ++S::m2; // good
        ++S::m3; // good
    }
    friend void doSomething2();
};
  
inline void doSomething2()
{
    ++S::m1; // good
    ++S::m2; // good
    ++S::m3; // good
}
  
class D: public S
{
    inline void doSomething3()
    {
        ++S::m1; // good
        ++S::m2; // good
        //++S::m3; // bad
    }
};
  
int main()
{
    ++S::m1; // good
    //++S::m2; // bad
    //++S::m3; // bad
}
  
int S::m1 = 0; // these lines
int S::m2 = 0; // are simply
int S::m3 = 0; // definitions

This code was developed by phantomotap.

Have questions about this code? Comments? Did you find a bug? Let me know!😀
Page created by G. (George) Samaras (DIT)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s