为什么这种隐式转换如何以及为何起作用

Why how and why this implicit conversion works

我不明白为什么 c1 = {1, 2, 3, 4} 和 c2 = {5, 6, 7, 8} 工作正常,没有声明的构造函数,编译器生成的编译器也没有'不适合。

我试图通过显式转换来理解:(C&) { 1, 2, 3, 4} 和 (const C&) { 1, 2, 3, 4},但它不起作用。如果编译器提供了带有初始化列表的默认构造函数,或者我从错误的方面来解决问题?

#include <cstdlib>
#include <iostream>
using namespace std;

namespace A001 {
class A { public: int a; double b; };
class B { public: int a; double b; };
class C { public: A a; B b; };
void test() {
    C c1 = { 1,2,3,4 }, c2 = { 5,6,7,8 };
        cout << c1.b.a + c2.a.b;
   }
}

这不是隐式转换,它是 aggregate initialization + brace elision。例如

C c1 = { 1,2,3,4 }

相当于

C c1{ {1,2}, {3,4} }