I am not able to understand why the 2nd ~Test() is called with different 'this' but the same string value ??
Also why does it give error, if I want to declare Test::Str as a const string member ??
Also why does it give error, if I want to declare Test::Str as a const string member ??
Code:
=======================================================
struct Test{
string Str; [B]// Gives error if, you declare const string ![/B]
Test(const string s) : Str(s) { cout<<Str<<" Test() "<<this<<endl; }
~Test() { cout<<Str<<" ~Test() "<<this<<endl; }
};
struct TestWrapper{
vector<Test> vObj;
TestWrapper(const string s) { vObj.push_back(s); }
~TestWrapper() { }
};
int main ()
{
TestWrapper obj("HELLO");
}
Output:
======
HELLO Test() 0x7fbffff700
HELLO ~Test() 0x7fbffff700
HELLO ~Test() 0x503040 [B]<------- Why ?[/B]
=======================================================
Comment