class CTest{ string name; CTest(string s) { name = s; Print("CTest::CTest() for " + name + "\n"); } ~CTest(){ Print("CTest::~CTest() for " + name + "\n"); } void test(){ Print("CTest::test() for " + name + "\n"); }}void test(){ CTest t1("Ent1"); CTest t2("Ent2"); t1.test(); t2.test(); // t2 = t1; // NOTE: see what happens if you uncomment this line}
When I run this it produces the following output:
CTest::CTest() for Ent1
CTest::CTest() for Ent2
CTest::test() for Ent1
CTest::test() for Ent2
CTest::~CTest() for Ent2
CTest::~CTest() for Ent1
This looks like what I 'd expect. But if I uncomment the last line in test() (the one with the "NOTE" comment), it outputs this:
CTest::CTest() for Ent1
CTest::CTest() for Ent2
CTest::test() for Ent1
CTest::test() for Ent2
CTest::~CTest() for Ent1
CTest::~CTest() for Ent1
CTest::~CTest() for Ent1
This does not look like what I 'd expect.
I 'm sure I 'm somehow misusing the language here but can someone explain to me what I 'm doing wrong?
Thanks,
Yiannis.