1
我看到人们使用反斜线时,他们中的宏定义功能:定义函数++
#define ClassNameNoDebug(TypeNameString) \
static const char* typeName_() { return TypeNameString; } \
static const ::Foam::word typeName
我做了一个非常简单的测试。但是我收到了一堆错误。测试代码如下: 在我testmacro.h文件:
#define declearlarger(first,second) \
double whichislarger(double first,double second){ return (first>second) ? fisrt : second;}
在我的main()函数:
int second =2;
int first =1;
cout << declearlarger(first,second) << endl;
的错误是:
/home/jerry/Desktop/backslash/backslash_test/testmacro.h:7: error: expected primary-expression before 'double'
double whichislarger(double first,double second){ return (first>second) ? fisrt : second;}
^
/home/jerry/Desktop/backslash/backslash_test/testmacro.h:7: error: expected ';' before 'double'
double whichislarger(double first,double second){ return (first>second) ? fisrt : second;}
^
/home/jerry/Desktop/backslash/backslash_test/main.cpp:24: error: expected primary-expression before '<<' token
cout << declearlarger(first,second) << endl;
^
这一切结束我的测试错误。任何人都可以提出一些建议,为什么这些错误弹出?
你的宏定义了一个函数;它并没有称之为获得价值。你不能使用'<<'运算符将函数定义重定向到'cout'。它在C++中没有任何意义。另外,'fisrt'。 – crayzeewulf
'fisrt'有什么好笑的?我在Wome有一个叫做'fisrt'的vewy gweat fwiend! – user4581301
Touché,@ user4581301。 – crayzeewulf