为什么在下面的程序中没有注释掉行?将初始化列表传递给宏
#include <iostream>
#include <vector>
using namespace std;
#define F1(a) 1
int F2(vector<int>) { return 2; }
int main() {
vector<int> v;
v = vector<int>{1,2,3};
cout << F1(v) << endl;
//The following line doesn't compile. The error is:
//error: macro "F" passed 3 arguments, but takes just 1
//cout << F1(vector<int>{1,2,3}) << endl; // <- error!
cout << F1(vector<int>({1,2,3})) << endl;
cout << F1((vector<int>{1,2,3})) << endl;
cout << F2(v) << endl;
//The following line compiles fine
cout << F2(vector<int>{1,2,3}) << endl;
cout << F2(vector<int>({1,2,3})) << endl;
cout << F2((vector<int>{1,2,3})) << endl;
return 0;
}
的[ GCC在线文档](https://gcc.gnu.o rg/onlinedocs/cpp/Macro-Arguments.html)有一个很好的例子和解释。 –