运行时在main函数给x1赋值时报错,说是没有与参数列表匹配的构造函数X::X实例
#include<iostream>
#include<string>
using namespace std;
class X {
private:
char *s;
public:
X(char *b) {
s = new char[sizeof(b) + 1];
strcpy(s, b);
}
~X() { delete s; }
void display() { cout << "s=" << s << endl; }
};
void main() {
X x1("ok");
X x2(x1);
X x3 = x1;
x2.display();
x3.display();
system("pause");
}