c++ - VS2008 C++ "interface"作为参数名编译失败

标签 c++ visual-c++

正如标题所说,我在 VS2008 C++ 程序中遇到编译器错误。我不确定如何比用代码更好地描述我的问题。除非我取消注释 TEST 行,否则将编译以下内容。

#include <windows.h>
#include <iostream>
using namespace std;

//#define TEST //<-- uncomment for error
#ifdef TEST
void test(void* interface)
{
    return;
}
#endif
int main()
{
    cout << "Hello World" << endl;
    system("PAUSE");
    return(0);
}

取消注释时出现以下错误:

1>main.cpp(7) : error C2332: 'struct' : missing tag name
1>main.cpp(7) : error C2144: syntax error : '<unnamed-tag>' should be preceded by ')'
1>main.cpp(7) : error C2144: syntax error : '<unnamed-tag>' should be preceded by ';'
1>main.cpp(7) : error C2059: syntax error : ')'
1>main.cpp(8) : warning C4094: untagged 'struct' declared no symbols
1>main.cpp(8) : error C2143: syntax error : missing ';' before '{'
1>main.cpp(8) : error C2447: '{' : missing function header (old-style formal list?)

这是非托管代码,所以我不确定接口(interface)这个词有什么问题。有没有办法让这段代码按原样编译,或者我是否必须将术语接口(interface)的每个实例更改为其他内容?

谢谢!

最佳答案

如果您的代码需要包含 Windows.h,那么您应该避免使用名称 interface,因为它是为 Windows SDK 为它保留的用途而保留的(本质上它是关键字 struct 的同义词)。可能有解决该问题的技巧(您可以在包含 SDK header 后 #undef interface),但您应该避免使用该标识符。

关于c++ - VS2008 C++ "interface"作为参数名编译失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10675077/

相关文章:

c++ - fstream 指针未指向

c++ - 确保单个实例并为 Windows C++ 控制台应用程序传递参数的正确方法

c++ - C++/CX 和 C++/WinRT 可以在同一个项目中使用吗?

multithreading - VC++中终止线程

visual-c++ - dll大小(调试和发布)

visual-c++ - 使用 Direct2D 绘制圆形进度条

c++ - 日期和时间选择器问题,无法重置日期或时间

c++ - 未命中内联函数中的断点

c - cvMemStorage的结构?

c++ - 成员的结构与命名空间的潜在范围