Why can a const member function modify a static data member?

Viewed 9970

In the following C++ program, modifying a static data member from a const function is working fine:

class A 
{
  public:   
    static int a; // static data member

    void set() const
    {
        a = 10;
    }
};

But modifying a non-static data member from a const function does not work:

class A 
{
  public:   
    int a; // non-static data member

    void set() const
    {
        a = 10;
    }
};

Why can a const member function modify a static data member?

4 Answers
Related