我們假設有四個文件:foo.h,foo.cpp,bar.h,bar.cpp。VC++ 2010:'缺少類型說明符'錯誤來來去去,沒有改變代碼
foo.h中:
#pragma once
class foo
{
// Whatever
};
Foo.cpp中
#include "foo.h"
// Foo's definitions
bar.h
#pragma once
class bar
{
bar(const foo & f); // < C4430 'missing type specifier' (not always)
// Other declarations
};
bar.cpp
#include "foo.h"
#include "bar.h"
// Bar's definitions
編譯器說有C4430在bar.h.但奇怪的是,我可以通過評論來構建代碼,然後取消註釋。當然,構建失敗,行也被評論,但是當我取消註釋時,我會成功構建。所以相同的代碼可能會或可能不會產生錯誤。
我的VS是10.0.40219.1 SP1Rel,並且項目類型是Win32 DLL。
儘可能清楚!非常感謝Luchian! – Yegor
@Yegor樂於幫助:) –
如果您只使用引用,而不僅僅是指針,那麼聲明也足夠。 – Xeo