Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- string stra = "1";
- string strb = "2";
- class A
- {
- public:
- string s;
- void* rawPtr = 0;
- A()
- {
- s = stra == "" ? strb : stra;
- stra = "";
- cout << "constructor " << s << endl;
- rawPtr = malloc(1);
- }
- ~A()
- {
- if(rawPtr)
- free(rawPtr);
- cout << "destructor " << s << ", ptr: " << (void*)s.data() << " = " << s.data() << endl;
- }
- #if 1 // FLIP ME
- A& operator=(A& o)
- {
- free(rawPtr);
- rawPtr = o.rawPtr;
- o.rawPtr = 0;
- cout << "assignment to: " << s << ", other is: " << o.s << endl;
- return *this;
- }
- #endif
- };
- class B
- {
- public:
- A a;
- string ssss;
- };
- void test()
- {
- B b;
- b = B();
- }
- int main()
- {
- test();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement