Saw some codes like below in a C++ project:
struct Foo{
std::wstring x;
//blah
}
// this func returns a Foo object
Foo getFoo(){
//blah
}
void main() {
Foo obj{getFoo()}; //why can initialize by another Foo object in {}?
}
{} is list-initialization. But no Foo arguments are listed here. Why does this work? Does struct have default copy constructor?
And does Foo obj(getFoo()) work? Any difference from the way of using {}?
Foohas an implicitly declared copy constructor; 2.Foo obj(getFoo())works too; 3. Same effect here.