部分代码:
char * a=new char[100];
string * p1,* p2;
p1=new (a) string("test1");
p2=new (a) string("test2");
cout<<p1<<endl;
cout<<p2<<endl;
运行结果:
test1
test2
问:
1.为什么说p2没有收到new运算符返回的地址?
2.既然没有收到地址那为什么可以正常输出?
cout<<*p1<<endl;
cout<<*p2<<endl;
弄错了不好意思
运行结果应该是:
test2
test2
p1,p2都指向字符数组a的地址。