可视 VS2008 C++ "interface"作为参数名称编译失败
visual VS2008 C++ "interface" as a parameter name fails to compile
正如标题所说,我在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?)
这是非托管代码,所以我不确定接口这个词有什么问题。 有没有办法让这段代码按原样编译,还是我必须将术语接口的每个实例都更改为其他内容?
谢谢!
如果你
的代码需要包含Windows.h
那么你应该避免使用名称interface
,因为它是为Windows SDK保留的使用而保留的(本质上它是关键字struct
的同义词(。 可能有技巧可以解决这个问题(您可以在包含 SDK 标头后#undef interface
(,但您可能应该避免使用该标识符。
单词
interface
由MSVC++保留,因为它是Microsoft编译器添加的非标准keyword
,用于定义MSVC++中的接口。
为参数使用不同的名称,如下所示:
#ifdef TEST
void test(void* test_interface)
{
return;
}
#endif
相关文章:
- 包含模板文件的递归会导致编译失败
- 提升 1.64 单元测试编译失败
- C++模板的模板编译失败
- 使用已删除的函数进行编译失败,并显示 uclibc
- MinGW-w64 编译失败,nullptr_t
- 使用提升线程时编译失败
- 编译花絮 g++, clang++, 使用 libboost -- g++8 编译失败时 g++7 成功;
- CMake + Qt,moc 编译失败,无法实现 QMetaObject 方法(编译器找不到基本 ui 对象的标头?
- 带有引用的std::tuple在clang中编译失败,但在gcc中编译失败
- 解决由于在哈希函数中使用了不完整的类型而导致的编译失败
- 将XCode升级到verison 11.1后,C++编译失败
- 添加类型名会导致程序编译失败
- 将 qi::lexeme 添加到灵气中的规则时编译失败
- 如果我在下面的代码中使用 list 而不是 vector,为什么在我尝试在迭代器之间执行减法的行中编译失败?
- 返回 std::stringstream - 编译失败
- 编译失败:strlen 不是 std 的成员
- MSBuidel - 将资源文件添加到项目后静态库编译失败
- C++ - 在 std::thread 中调用重载函数时编译失败
- QtWebEngine 到嵌入式 Linux 交叉编译失败
- 使用 glibc 2.7 包含路径编译失败