1 つの定義規則について、同じトークンが同じ順序である場合、複数の翻訳単位でクラスを定義できることはわかっていますが、このプログラムは私には奇妙です
ファイルmain.cpp
#include "Source.h"
struct mystructure
{
int field1;
float field2;
};
int main()
{
mystructure myvar;
myvar.field2= 2.0f;
myCustomFunction(myvar);
return 0;
}
ファイルSource.h
struct mystructure;
void myCustomFunction(mystructure& vv);
ファイルSource.cpp
#include "Source.h"
struct mystructure
{
char otherfield;
int anotherone;
bool anotheranotherone;
};
void myCustomFunction(mystructure& vv)
{
vv.otherfield = 'A';
}
私は MSVC2012 を使用していますが、コンパイラは文句を言いません。何故ですか?それは正常ですか?