For below code, is there any reason compiler will choose non-explicit constructor..
struct S {
S() = default;
explicit S(S & cp) {
std::cout << "explicit" << std::endl;
}
S(const S & cp) {
std::cout << "copy" << std::endl;
};
};
int main() {
S s1;
S s2 = {s1};
}
from https://en.cppreference.com/w/cpp/language/list_initialization, it says for copy-list-ini... both explicit and non-explicit constructors are considered, but only non-explicit constructors may be called
https://godbolt.org/z/YqWWs9jqY
Aucun commentaire:
Enregistrer un commentaire