Skip to content

Instantly share code, notes, and snippets.

@marchelbling
Created August 17, 2012 10:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marchelbling/3377946 to your computer and use it in GitHub Desktop.
Save marchelbling/3377946 to your computer and use it in GitHub Desktop.
Dummy code to check that a const object attributes are const
#include <iostream>
class A
{
public:
A (int a = 0) : m_a (a)
{ }
~A ()
{ }
int get () const
{ return m_a; }
void set (int a)
{ m_a = a; }
private:
int m_a;
};
class B
{
public:
B(int a = 0) : m_a (0)
{ m_a = new A (a); }
~B()
{ if (m_a) delete m_a; }
int get () const
{ return m_a->get (); }
void set (int a)
{ return m_a->set (a); }
private:
A* m_a;
};
int main ()
{
B const a(0);
std::cout << "value: " << a.get () << std::endl;
//a.set (17); //KO
//std::cout << "value: " << a.get () << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment