Created
July 14, 2014 13:20
-
-
Save thallippoli/83d6063001e3d1822a27 to your computer and use it in GitHub Desktop.
The Other Side of Const
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using namespace std; | |
#include <iostream> | |
class Foo | |
{ | |
public: | |
void SetX( int x ) | |
{ | |
m_x = x; | |
} | |
int GetX() | |
{ | |
return m_x; | |
} | |
private: | |
int m_x; | |
}; | |
class Bar | |
{ | |
public: | |
Bar( Foo * pFoo ) | |
{ | |
m_pFoo = pFoo; | |
} | |
void Constfunc() const | |
{ | |
m_pFoo->SetX( 42 ); | |
m_foo.SetX( 42 ); | |
} | |
private: | |
Foo * m_pFoo; | |
Foo m_foo; | |
}; | |
int main( void ) | |
{ | |
Foo foo; | |
foo.SetX( 0 ); | |
Bar bar( &foo ); | |
bar.Constfunc(); | |
cout << foo.GetX(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment