Skip to content

Instantly share code, notes, and snippets.

@thallippoli
Created July 14, 2014 13:20
Show Gist options
  • Save thallippoli/83d6063001e3d1822a27 to your computer and use it in GitHub Desktop.
Save thallippoli/83d6063001e3d1822a27 to your computer and use it in GitHub Desktop.
The Other Side of Const
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