Sunday, 24 April 2016

Mutable storage class specifier IN C++

No comments:


                Usually data members cannot be modified when function is declared as const. If there is situation that even if function is declared data member need to be modified due to unavoidable situation. To achieve this declare the data member with mutable specifier.


class test
   int a;
   mutable int b;

   void updateConstFunc()const

      // a=1; ==> Not possible since function is const
      b=2; //==> possible since mutable specified

int main()
   test t;
   return 0;

No comments:

Post a Comment