Visual c++ 调用另一个类';成员函数中的构造函数
我在类“box”中创建了一个指针数组,并调用一个函数put_in_box来创建一个新的“things”类obj,并将索引指针指向它。运行本地调试器时,提示错误C2514“things”:类没有构造函数。如果我删除box类定义中的行“index[j]=newthings(j);”,我将能够通过在main函数中使用“blue_box.index=newthings(2);”获得预期的结果 我的问题是:类确实有构造函数,为什么我不能从另一个类的成员函数调用它?有没有办法做同样的工作Visual c++ 调用另一个类';成员函数中的构造函数,visual-c++,Visual C++,我在类“box”中创建了一个指针数组,并调用一个函数put_in_box来创建一个新的“things”类obj,并将索引指针指向它。运行本地调试器时,提示错误C2514“things”:类没有构造函数。如果我删除box类定义中的行“index[j]=newthings(j);”,我将能够通过在main函数中使用“blue_box.index=newthings(2);”获得预期的结果 我的问题是:类确实有构造函数,为什么我不能从另一个类的成员函数调用它?有没有办法做同样的工作 #include
#include <iostream>
using namespace std;
class box;
class things;
class box {
public:
things *index[50];[![enter image description here][1]][1]
void put_in_things(int j) {
index[j] = new things(j);
}
};
class things {
public:
int i;
things(int i_) :i(i_) { cout << "things constructed" << endl; }
things(things&c) {
i = c.i;
}
~things(){}
};
int main() {
box blue_box;
blue_box.put_in_things(1);
blue_box.index[1] = new things(2);
return 0;
#包括
使用名称空间std;
类框;
阶级事物;
类框{
公众:
事物*索引[50];[![在此处输入图像描述][1][1]
虚空放在事物中(int j){
指数[j]=新事物(j);
}
};
阶级事务{
公众:
int i;
事物(int ii):i(ii){cOutC++使用一个PASS编译模型。在PutsIn thths[]方法中,它对事物类不知道任何东西。你必须将方法定义移到事物类声明之外。非常感谢,问题解决了。