zzllvlv 2020-06-02 13:55 采纳率: 100%
浏览 651
已采纳

qt 中结构体添加构造函数后报错

我定义了一个结构体并添加了构造函数:

struct DataInfo{
    GLenum       type;
    const char*  filename;
    int       note;
    DataInfo(){
        type = 0;
        filename = nullptr;
        note = 0;
    }
};

但是在初始化一个结构体时:

DataInfo pain = {1,"../texture/red.file",null};

qt报错:could not convert '{1, "../texture/red.file"}' from 'brace-enclosed initializer list' to 'ShaderInfo'

  • 写回答

2条回答 默认 最新

  • 小学狗喵喵叫 2020-06-02 14:27
    关注
    struct DataInfo{
        GLenum       type;
        char*  filename;
        int       note;
        DataInfo(GLenum ptype, const char*  pfilename,int pnote){
            type = ptype;
            strcpy(filename,pfilename);
            note = pnote;
        }
    };
    /*************************/
    DataInfo pain((GLenum)1,"../texture/red.file",0);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 已采纳回答 8月13日