当我尝试在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)
谢谢你的帮助