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