using namespace std;
class C {
public:
char *s;
C(const char *s0) {
s = new char[strlen(s0)+1];
strcpy(s,s0);
}
C(C &c) {
s = new char[strlen(c.s)+1];
strcpy(s,c.s);
}
};
int main(int argc, char* argv[]) {
C c("cde");
C c0(c);
cout << c.s << endl;
cout << c0.s << endl;
c.s[1] = 'X';
cout << c.s << endl;
cout << c0.s << endl;
}
I'm not so sure what is happening with the pointers and references. Can anyone explain why the output for the second c0.s is still "cde"? Thank you.