C++ 错误:在‘;之前应为主表达式’;代币铸造发行
我试图弄清楚为什么在初始化结构成员变量期间,我会在该转换中出现编译错误(在该消息的标题中) 在我的班级里C++ 错误:在‘;之前应为主表达式’;代币铸造发行,c++,c,struct,malloc,C++,C,Struct,Malloc,我试图弄清楚为什么在初始化结构成员变量期间,我会在该转换中出现编译错误(在该消息的标题中) 在我的班级里 class MyClass { ... public: struct cpresets { char* soundfont_key; char* exists; UT_hash_handle hh; }; ... }; 在myclass.cc中 void mycl
class MyClass {
...
public:
struct cpresets {
char* soundfont_key;
char* exists;
UT_hash_handle hh;
};
...
};
在myclass.cc中
void myclass::mymethod() {
...
struct cpresets *newpreset;
newpreset = (cpresets*) malloc(sizeof( cpresets));
...
}
...
typedef struct {
...
}mystruct;
...
static instantiate(){
...
//this line causes the compile error
mystruct* me = (mystruct*) malloc(sizeof(mystruct));
...
}
cc文件中还有另一个地方可以执行此操作
在myclass.cc中
void myclass::mymethod() {
...
struct cpresets *newpreset;
newpreset = (cpresets*) malloc(sizeof( cpresets));
...
}
...
typedef struct {
...
}mystruct;
...
static instantiate(){
...
//this line causes the compile error
mystruct* me = (mystruct*) malloc(sizeof(mystruct));
...
}
我看到它工作的情况下的区别是,结构是在cc文件中定义的,而在它不工作的情况下,结构是类头的成员VARABLE。你知道为什么这是一个问题,或者我可以做些什么来解决它吗
谢谢。您错过了
static instantiate()
的返回类型,应该是
static void instantiate()
实际上分号在文件中。我编辑了示例,指出哪一行给出了错误。前两个代码块没有指示,第三个代码块说“这一行导致错误”,但第三个代码块前的文本说“这有效”