我在结构的构造函数中遇到此错误。为什么我得到它,因为我只使用 * 指针而不是 **。
错误:
\ListStruc.cpp:26:25: error: cannot convert 'int**' to 'int*' in assignment
结构.h
struct Arr{
int days;
int *M;
};
typedef Arr* Array;
结构.cpp
void constr(Array &o){
//Construct of 1*31 Matrix
o=new Arr;
o->days = days;
o->M = new int*[o->days];
最佳答案
因为 M
是一个 int*
,正确的初始化应该是:
o->M = new int[o->days];
关于c++ - 动态结构错误,指针转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10112787/