class P {
public:
explicit P(int a, int b, int c) {
std::cout<<"calling explicit constructor"<<"\n";
}
};
int main() {
P z {77,5,42}; // OK
P w = {77,5,42}; // ERROR due to explicit (no implicit type conversion allowed)
}
我认为{77,5,42}
具有隐式类型std::initialization_list<int>
。如果是这种情况,不会导致建造变量z
的失败?使用std :: initializer_list显式构造函数和初始化
'{77,5,42}'没有类型。 –
谢谢,澄清。 – mavam