class CStrok { public: char* m_pstr; }; void main() { CStrok a; CStrok b; a.m_pstr = new char[4]; a.m_pstr = "one"; b = a; b.m_pstr = "two"; cout << b.m_pstr << endl; cout << a.m_pstr << endl; return; }
If I correctly understood the pointers, then when b = a, the address of the string "one" is copied from variable a into variable b, and when a different string is assigned to pointer b, the string in a must also change. and the pointers to variables a and b point to the same address. However, when strings are output, they are different. What's wrong ?