相关疑难解决方法(0)

支撑数如何影响均匀初始化?

请考虑以下代码段:

#include <iostream>

struct A {
  A() {}
  A(const A&) {}
};

struct B {
  B(const A&) {}
};

void f(const A&) { std::cout << "A" << std::endl; }
void f(const B&) { std::cout << "B" << std::endl; }

int main() {
  A a;
  f(   {a}   ); // A
  f(  {{a}}  ); // ambiguous
  f( {{{a}}} ); // B
  f({{{{a}}}}); // no matching function
}
Run Code Online (Sandbox Code Playgroud)

为什么每个调用都会编写相应的输出?支撑数如何影响均匀初始化?支撑精益如何影响这一切?

c++ language-lawyer uniform-initialization c++11 list-initialization

31
推荐指数
1
解决办法
710
查看次数