extern关键字"缺少类型说明符"

Ric*_* Li 5 c c++ extern

我正在使用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
Run Code Online (Sandbox Code Playgroud)

Required.h

#pragma once
//include Windows.h, and the SDK
#include "ValveInterfaces.h"

extern ValveInterfaces* VIFace; //this line errors
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

错误的屏幕截图:http: //i.imgur.com/lZBuB.png

pax*_*blo 4

第一个错误:

error C2143: syntax error : missing ';' before '*'
Run Code Online (Sandbox Code Playgroud)

这是一个致命的泄露,表明该ValveInterfaces类型在您第一次尝试使用它时尚未定义

这种情况几乎总是会发生,因为 的类型ValveInterfaces未知。这有点很难说,因为你已经删除了大量的内容ValveInterfaces.h,但是,即使它在那里定义,它也可能是一个奇怪的组合,#pragma once并且包含卫士的明显错位_REQUIRED_H(它们通常位于required.h),这会让你感到悲伤。

  • 我已将整个 ValveInterfaces.h 粘贴到里面。我认为我的问题是 ValveInterfaces.h 包含Required.h,它也包含ValveInterfaces.h。 (3认同)