编译错误“”struct“type redefinition”虽然它是它的第一个定义 [英] Compile error "'struct' type redefinition" although it's the first definition for it
问题描述
一切都运行良好,直到我把一些代码从主文件移动到一个新类,然后我有以下错误:
Everything was working well untill I moved some code from the main file to a new class, then I had the following error:
错误C2011:'color1':'struct'type redefinition
error C2011: 'color1' : 'struct' type redefinition
struct color1
{
color1()
{
red = green = blue = 0;
}
color1(float _red, float _green, float _blue)
{
red = _red;
green = _green;
blue = _blue;
}
float red, green, blue;
};
有什么想法吗?
推荐答案
如果编译器说它被重新定义,那么它可能是。
If the compiler says it's redefined, then it probably is.
我的心理调试技巧告诉我你将结构从源文件一个头文件,并且忘记在头文件中的include guard,然后在源文件中包含多次。
My psychic debugging skills tell me that you moved the struct from a source file to a header file, and forget the include guards in that header, which is then included multiple times in a source file.
编辑:作为一般规则,我通常建议避免引导下划线。在某些情况下(例如后面跟着一个大写字母),它们被保留用于实现,最简单的是不要使用领导 _
,而不是希望你记住所有的规则。
As a general rule I generally suggest avoiding leading underscores. In some cases (for example followed by a capital letter) they're reserved for the implementation and it's simplest to just never use leading _
instead of hoping you remember all the rules.
这篇关于编译错误“”struct“type redefinition”虽然它是它的第一个定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!