Learning  C++
Home
Tutorials
C++  Programs
Contact  us
Sitemap
// Program to illustrate constant object example


#include<iostream.h>

class sample
{

     public:
          int a;
          sample()
          {
          }

          void func()
          {
          }
} ;

int main()
{
     const sample obj;
     obj.a=23;  // error cannot modify a const object
     cout<<"\n"<<obj.a;
     obj.func(); // error non-const member function called on a const object
     return 0;
}