C++中的括号或大括号如何改变变量的初始值?
只是一个有启发性的面试问题:“这个 C++14 程序打印什么?”
#include <iostream>
struct A { int i; };
struct B {
A a{1};
operator int() { return a.i; }
};
int main() {
B x({});
B y{{}};
std::cout << x << y;
}
它实际上打印了10,这意味着定义中的大括号y改变了它的初始值。但是如何?