小编Abd*_*ami的帖子

g ++ 4.8.5:未使用##给出有效的预处理令牌

当我尝试在Linux中使用G ++ 4.8编译程序时出现错误“未提供有效的预处理令牌”。并且在Solaris中使用CCSuntudio进行编译时没有错误。

在我的代码下面:

#include <iostream>

#define func(type1,varname1) \
        cout << "ma var est "<<##varname1<<" et le type est "<<#type1; \
        cout <<endl;

using namespace std;

int main() {
  func("int", "area");
}

Run Code Online (Sandbox Code Playgroud)

它可以在CCSunStudio中完美运行,但不适用于G ++

hello.hxx:2:23: error: pasting "<<" and ""area"" does not give a valid preprocessing token
  cout << "ma var est "<<##varname1<<" et le type est "<<#type1; \
                       ^
hello.cxx:7:1: note: in expansion of macro ‘func’
 func("int","area");
 ^
Run Code Online (Sandbox Code Playgroud)

谢谢你的帮助

c++ preprocessor g++ c-preprocessor

0
推荐指数
1
解决办法
67
查看次数

标签 统计

c++ ×1

c-preprocessor ×1

g++ ×1

preprocessor ×1