fork download
  1. #include <stdio.h>
  2.  
  3. class A
  4. {
  5. A* p;
  6. int m_Value;
  7. public:
  8. A():p(this),m_Value(0){}
  9. int GetValue( void ) const { return m_Value; }
  10.  
  11. // const member function
  12. void SetValue( int value ) const { p->m_Value = value; }
  13. };
  14.  
  15. int main( void )
  16. {
  17. const A a;
  18. printf( "%d\n", a.GetValue() );
  19. a.SetValue( 5 );
  20. printf( "%d\n", a.GetValue() );
  21. return 0;
  22. }
Success #stdin #stdout 0s 2684KB
stdin
Standard input is empty
stdout
0
5