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'

c++

1个回答

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);
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问