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'
答
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);
答
你应该从头好好学一下多态。