【问题标题】:Dyanmic structure error, pointers conversion动态结构错误,指针转换
【发布时间】:2012-04-11 19:40:46
【问题描述】:

我在结构的构造函数中收到此错误。为什么我会得到它,因为我只使用 * 指针而不是 **。

错误:

\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];

【问题讨论】:

    标签: c++ arrays pointers dynamic-allocation


    【解决方案1】:

    由于Mint*,正确的初始化应该是:

    o->M = new int[o->days];
    

    【讨论】:

    • 谢谢 >.> 我如何用一个类的对象初始化数组我得到错误 int 不能转换为 Expre,expe beeing 我的类。
    • @BogdanMaier 我真的没听懂你刚才说的话。
    • 我修复了错误。现在我很期待创建那个数组,一个类对象数组是我必须在构造函数/头文件中声明还是我应该怎么做,因为类不是类型,我不知道我应该怎么做?
    • @BogdanMaier 你可以问另一个问题。确保包含您尝试编写的新代码。顺便说一句,类是类型。 struct 和 class 的唯一区别是类成员默认是私有的。
    • @BogdanMaier 也许你应该对你现在拥有的代码和你想要实现的目标提出一个新问题。
    猜你喜欢
    • 1970-01-01
    • 2016-11-10
    • 1970-01-01
    • 2012-05-06
    • 2016-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多