c++中不能用new创建一个类的对象数组??


include <iostream>

using namespace std;
class text
{
public:


 text(int m,int n): a(m),b(n){}
int a;
int b;

};

int main()
{


 **text *p=new text[2]**;/*用p指向创建的对象数组*/
...
return 0;

}

尝试用以上代码用new创建一个对象数组,发现不行,是哪里不对吗?
为什么用new又可以为结构体创建对象数组?

class类 new C++

felgod 9 years, 11 months ago

加个无参数的构造函数试试 text(){}

kactus answered 9 years, 11 months ago

Your Answer