我无法理解为什么我要重新定义试图运行这个例子。有谁能告诉我?
using namespace std;
class Base {
protected: int *value;
public: Base() {
value = new int,
*value = 1;
};
Base(int &n) {
value = new int[n];
}
};
int main() {
int x=2;
Base zm;
Base(x);
system("Pause");
}
答案 0 :(得分:0)
Witaj Przemeku Na StackOverflow!
这个怎么样?:
class Base {
protected: int *value;
public:
Base() {
value = new int,
*value = 1;
};
Base(int &n) {
value = new int[n];
};
};
int main()
{
int x;
x = 2;
Base base;
base = Base(x); <--- fix
return 1;
}
Proszębardziejmagformowaćkod! ;)强>