I have a question about implicit constructors. So let's say I have the following scenario:
struct MyStruct1 {
bool myBool1 = false;
bool myBool2 = false;
MyStruct1() = default;
MyStruct1(bool val)
: myBool1(val)
, myBool2(val)
{}
};
struct MyStruct2 {
MyStruct1 myStruct1;
};
Now what I want to know is if 1 and 2 are equivalent below:
1)
int main() {
MyStruct2 myStruct2;
myStruct2.myStruct1 = true;
}
int main() {
MyStruct2 myStruct2;
myStruct2.myStruct1 = MyStruct1{true};
}
Is that how implicit constructors works? Or is there something else at play here?
question from:https://stackoverflow.com/questions/65925572/c-how-does-implicit-construction-work-struct-initialization