[英]How can I remove the VS warning C4091: 'typedef ' : ignored on left of 'SPREADSHEET' when no variable is declared
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'应包含的内容......
Delete typedef
. 删除
typedef
。 It's the C way of declaring structs, C++ does it automatically for you. 这是声明结构的C方式,C ++会自动为您完成。
You need to add some identifier before the terminating ;
您需要在终止之前添加一些标识符
;
, eg: ,例如:
typedef struct BLAH { ... } BLAH;
Just remove " typedef
". 只需删除“
typedef
”即可。 You declare a new struct and the typedef
keyword isn't used for that. 您声明了一个新结构,并且不使用
typedef
关键字。 You would use typedef
to define a new name for an existing type, like this: 您可以使用
typedef
为现有类型定义新名称,如下所示:
typedef int number;
Yes, the BLAH
after the closing brace is important to make the typedef
a valid one. 是的,关闭括号后的
BLAH
对于使typedef
成为有效的很重要。 You can remove the SPREADSHEET
from the present place and keep it in between the }
and the ;
您可以从当前位置删除
SPREADSHEET
并将其保存在}
和;
之间;
. 。
My interpretation of this warning is that the compiler is indicating that the typedef
keyword is unnecessary because a variable is not being declared. 我对此警告的解释是编译器指示
typedef
关键字是不必要的,因为未声明变量。 and therefore if the intention of the code is to simply declare a struct
the typedef
is superfluous. 因此,如果代码的意图是简单地声明一个
struct
那么typedef
是多余的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.