Created
August 17, 2012 10:57
-
-
Save marchelbling/3377946 to your computer and use it in GitHub Desktop.
Dummy code to check that a const object attributes are const
This file contains 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
#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