【发布时间】:2020-02-26 17:50:14
【问题描述】:
当我尝试在 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");
}
它在 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");
^
感谢您的帮助
【问题讨论】:
-
错误消息非常明确,并描述了错误是什么。那么你的问题是什么?
-
<<和"area"不是有效的预处理器令牌,因此您不能将它们##放在一起。我猜你可能打错字了,意思是#单个哈希。
标签: c++ g++ c-preprocessor preprocessor