c++ - 如何摆脱警告 C4518 : storage-class or type specifier(s) unexpected here; ignored

标签 c++ visual-studio

我继承了一个旧的 C++ DLL 项目。它使用 VS 6.0 编译。

这是一个已经工作多年的东西。

我在构建项目时首先注意到的是一些通常与缺少分号有关的警告,但事实并非如此,请看一下:

头文件中的警告:

someproject\include\somefile.h(27) : warning C4518: '__declspec(dllexport) ' : storage-class or type specifier(s) unexpected here; ignored

代码:

#ifdef __cplusplus
extern "C" {
#endif
    VOID    DLLExport WINAPI func1        (unsigned char  *c, SHORT b, BOOL bIsChar, SomeTask* spTask);

    VOID    DLLExport WINAPI func2        (unsigned char  *c, SHORT b, BOOL bIsChar, SomeTask* spTask);
    PBYTE   DLLExport WINAPI func3          (PBYTE cpStr, BYTE cCh);
    SomeTask*   DLLExport WINAPI TaskPtr(VOID); // <- Ofending line

cpp文件中的警告:

someproject\somecode.cpp(3264) : warning C4518: '__declspec(dllexport ) ' : storage-class or type specifier(s) unexpected here; ignored

代码:

extern "C" SomeTask* DLLExport WINAPI TaskPtr(VOID)
{
    blah(); 
    blah(); 

类(class)代码:

class SomeTask
{
public:
    SomeTask(){}
            etc

最佳答案

该消息似乎暗示 dllexport(winapi) 是一种语言扩展,其行为类似于存储类或类型说明符。这些术语可以以任何顺序出现,但通常存储类出现在类型之前:我们说 static int 而不是 int static。此代码使用了不寻常的顺序,并且显然不受旧编译器的支持。但在这种情况下,除非您构建 DLL,否则这无关紧要。

关于c++ - 如何摆脱警告 C4518 : storage-class or type specifier(s) unexpected here; ignored,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18027010/

相关文章:

c++ - 在 Windows 小型转储文件中嵌入线程名称

visual-studio - Visual Studio 2012 不兼容且编辑器包未正确加载?

c++ - 应该 std::auto_ptr<>::operator = 重置/取消分配其现有指针?

C++:为什么此代码仅在使用 '\n' 时才有效?

java - 服务器内存有限的图像处理

c++ - ASM JUMP 指令和 C/C++ 中的指针之间的主要区别是什么

c++ - 当程序员尝试以从未设计使用的方式使用它时,C++ 是否显示出它的时代?

c++ - Windows 上来自 std::error_code 的 "unknown error"

c++ - 如何从 Windows 8 C++/WinRT 组件使用 OutputDebugString

c++ - 使用 SDL 在 C++ 中创建图形类