所以我知道代码中的大括号不仅仅意味着initializer_list
: 如果不是initializer_list,大括号括起来的列表是什么? https://stackoverflow.com/q/37682392/2642059
但他们应该做什么default to?
例如,假设我定义了一个重载函数:
void foo(const initializer_list<int>& row_vector) { cout << size(row_vector) << "x1 - FIRST\n"; }
void foo(const initializer_list<initializer_list<int>>& matrix) { cout << size(matrix) << 'x' << size(*begin(matrix)) << " - SECOND\n"; }
If I call foo({ 1, 2, 3 })
the 1st will obviously be called. And if I call foo({ { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } })
the 2nd will obviously be called.
但是如果我打电话怎么办:
foo({ { 1 }, { 2 }, { 3 } })
是那些嵌套的大括号吗int
-初始化器或initializer_list<int>
初始化器?gcc 说它不明确 http://ideone.com/3DsWe7但是如果你使用该代码并运行它http://webcompiler.cloudapp.net/ http://webcompiler.cloudapp.net/Visual Studio 表示它只是构建一个initializer_list<int>
。谁是对的?这里应该有一个默认值吗?