我使用Visual C++ Express創建了一個DLL,並且在Required.h
內聲明 extern ValveInterfaces* VIFace
時,編譯器告訴我沒有定義ValveInterfaces
。 (我要揭露VIFace
到包括Required.h
任何文件)extern關鍵字「缺少類型說明符」
這裏是我的文件結構:
DLLMain.cpp
#include "Required.h" //required header files, such as Windows.h and the SDK
ValveInterfaces* VIFace;
//the rest of the file
Required.h
#pragma once
//include Windows.h, and the SDK
#include "ValveInterfaces.h"
extern ValveInterfaces* VIFace; //this line errors
ValveInterfaces.h
#pragma once
#ifndef _VALVEINTERFACES_H_
#define _VALVEINTERFACES_H_
#include "Required.h"
class ValveInterfaces
{
public:
ValveInterfaces(void);
~ValveInterfaces(void);
static CreateInterfaceFn CaptureFactory(char *pszFactoryModule);
static void* CaptureInterface(CreateInterfaceFn fn, char * pszInterfaceName);
//globals
IBaseClientDLL* gClient;
IVEngineClient* gEngine;
};
#endif
錯誤的截圖: http://i.imgur.com/lZBuB.png
您不應該使用保留名稱作爲include guard。雖然它不是你的特定問題的原因(這是由於'ValveInterfaces.h'和'Required.h'的循環包含),它可能會導致[類似的問題](http://stackoverflow.com/questions/3345159/在-C-什麼那麼特殊之處的舉動-H)。 – 2012-01-16 11:35:39