下面是代码,但我不知道如何使用它。有人能帮我吗?错误无效从'int *'转换为'int'-fpermissive
#include <iostream>
using namespace std;
class CSample
{
int *x;
int N;
public:
//dafualt constructor
CSample(): x(NULL)
{}
void AllocateX(int N)
{
this->N = N;
x = new int[this->N];
}
int GetX()
{
return x;
}
~CSample()
{
delete []x;
}
};
int main()
{
CSample ob1; //Default constructor is called.
ob1.AllocateX(10);
//problem with this line
CSample ob2 = ob1; //default copy constructor called.
CSample ob3; //Default constructor called.
//problem with this line
ob3 = ob1; //default overloaded = operator function called.
}
GetX应该是int *类型或返回int类型。您也没有定义复制构造函数。请确保在将来正确设置问题的格式,并提供最小,完整和可验证的示例。 –
“我不知道如何调试” - 请看看[如何调试小程序](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/ )由Eric Lippert撰写,它是关于调试技术的*优秀*文章。 – EJoshuaS