【发布时间】:2012-01-16 07:46:07
【问题描述】:
我正在使用 Visual C++ Express 创建一个 DLL,并且在声明时
extern ValveInterfaces* VIFace 在Required.h 内,编译器告诉我ValveInterfaces 没有定义。 (我想将VIFace 暴露给任何文件,包括Required.h)
这是我的文件结构:
DLLMain.cpp
#include "Required.h" //required header files, such as Windows.h and the SDK
ValveInterfaces* VIFace;
//the rest of the file
必填.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
【问题讨论】:
-
您不应该使用保留名称作为包含守卫。虽然这不是您的特定问题的原因(这是由于循环包含
ValveInterfaces.h和Required.h),但它可能导致 similar problems。