我知道对于一个定义规则,如果它们以相同的顺序具有相同的标记,我可以在多个翻译单元中定义一个类,但是这个程序对我来说很奇怪
文件main.cpp
#include "Source.h"
struct mystructure
{
int field1;
float field2;
};
int main()
{
mystructure myvar;
myvar.field2= 2.0f;
myCustomFunction(myvar);
return 0;
}
文件来源.h
struct mystructure;
void myCustomFunction(mystructure& vv);
文件源.cpp
#include "Source.h"
struct mystructure
{
char otherfield;
int anotherone;
bool anotheranotherone;
};
void myCustomFunction(mystructure& vv)
{
vv.otherfield = 'A';
}
我正在使用 MSVC2012,编译器没有抱怨。这是为什么?这正常吗?