我有这个功能,它自己添加一个数字。#define ADD(x)(x)+(x)返回错误结果
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
#define ADD(x) (x)+(x)
int main()
{
int x = 2;
int y = ADD(++x);
cout << y << endl;
}
当我运行这个程序,它会返回8,但我还是希望6.
我想X = 3,这是送3 ADD功能,但现在看来似乎没有。有人可以向我解释吗?
如果您只是调用ADD(2),它会返回什么? –
这是创建内联函数的旧方法。现在尝试不这样做。 –
[C中宏需要括号](http://stackoverflow.com/q/10820340/995714) –