C++ 如何删除 VS 警告 C4091: 'typedef ' : 当没有声明变量时,在 'SPREADSHEET' 的左侧被忽略
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/913344/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I remove the VS warning C4091: 'typedef ' : ignored on left of 'SPREADSHEET' when no variable is declared
提问by Wartin
This warning is triggered multiple times in my code by the same declaration, which reads :
此警告在我的代码中由同一个声明多次触发,内容如下:
// Spreadsheet structure
typedef struct SPREADSHEET
{
int ID; // ID of the spreadsheet
UINT nLines; // Number of lines
void CopyFrom(const SPREADSHEET* src)
{
ID = src->ID;
nLines = src->nLines;
}
};
I don't want to just turn off that warning,
我不想只是关闭那个警告,
but rather change the code so that the warning doesn't come up !
而是更改代码,以免出现警告!
NOTE : I don't want to declare any variables here (it's a header file), only define what the struct 'SPREADSHEET' should include...
注意:我不想在这里声明任何变量(它是一个头文件),只定义结构“SPREADSHEET”应该包含的内容......
回答by Blindy
Delete typedef
. It's the C way of declaring structs, C++ does it automatically for you.
删除typedef
。这是声明结构的 C 方式,C++ 会自动为您完成。
回答by MSN
You need to add some identifier before the terminating ;
, e.g.:
您需要在终止之前添加一些标识符;
,例如:
typedef struct BLAH { ... } BLAH;
回答by sth
Just remove "typedef
". You declare a new struct and the typedef
keyword isn't used for that. You would use typedef
to define a new name for an existing type, like this:
只需删除“ typedef
”。您声明了一个新的结构,而typedef
关键字不用于该目的。您将使用typedef
为现有类型定义新名称,如下所示:
typedef int number;
回答by Srikant
Yes, the BLAH
afterthe closing brace is important to make the typedef
a valid one. You can remove the SPREADSHEET
from the present place and keep it in between the }
and the ;
.
是的,右大括号BLAH
之后的对于使之typedef
有效很重要。您可以SPREADSHEET
从当前位置删除 ,并将其保留在}
和之间;
。
回答by Neoheurist
My interpretation of this warning is that the compiler is indicating that the typedef
keyword is unnecessary because a variable is not being declared. and therefore if the intention of the code is to simply declare a struct
the typedef
is superfluous.
我对这个警告的解释是编译器指示typedef
关键字是不必要的,因为没有声明变量。因此,如果代码的意图是简单地声明struct
了typedef
是多余的。