语法错误:缺少';'在'*'之前 [英] Syntax error: missing ';' before '*'

查看:235
本文介绍了语法错误:缺少';'在'*'之前的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用vs2010定义结构数据类型

例如



i am defining a struct data type using vs2010
for example

//b.h head file
#include "a.h"
typedef struct myStruct
{

testStruct * m; //missing ';' before '*'


};





而teststruct是一个结构在ah文件中定义



问题是我错过了'';''之前''*''错误但如果我将testStruct直接放在bh文件中工作。

任何人都可以找出原因。谢谢..



while teststruct is a struct defined in a.h file

the problem is I got missing '';'' before ''*'' error but if i put the testStruct directly in the b.h file it works.
Can anyone figure out why .thanks..

推荐答案

你交换了你的typedef的参数 - 它是 typedef {{type}} {{typename}} ,所以你的typedef应该是

You swapped the arguments of your typedef - it''s typedef {{type}} {{typename}} , so your typedef should be
typedef struct {
  ...
} myStruct; 



这不会导致错误,但如果 testStruct 的typedef看起来相同,编译器没有得到它,因此没有把这个名字识别为类型名称。



PS:当然不需要在C ++中使用typedef这种情况(或ANSI C):你可以写:


This didn''t cause the error, but if the typedef for testStruct looks the same, the compiler didn''t get it, and therefore didn''t recognize that name as a type name.

P.S.: of course there is no need for a typedef in C++ in this case (or ANSI C for that matter): you can just write:

struct myStruct {
  ...
};



然后可以像使用typedef一样使用它:


and can then use it as you would a typedef:

void foo() {
   myStruct s;
}






我想,如果 testStruct 类型为 struct ,顾名思义,您可能会在它前面写上关键字 struct

Hi,

I think, that if testStruct is of type struct, as the name says, you shall probably write the keyword struct in front of it !
//b.h head file
#include "a.h"
struct myStruct
{
struct testStruct * m; //missing ';' before '*' 
};



希望这会有所帮助。



Best问候,

JK


Hope this helps.

Best regards,
J.K.


我建​​议按标准MS方式行驶

I would suggest going by the standard MS Way
#include "a.h"
typedef struct tagMyStruct
{

struct testStruct * m;


}ST_MYSTRUCT, *PST_MYSSTRUCT;


这篇关于语法错误:缺少';'在'*'之前的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆