I do have a struct
struct MyStruct {
MyStruct( XML cfg ) { ... }
int m_1, m_2, ... ;
}
And a class
class MyBaseClass {
public:
MyBaseClass() {}
MyStruct m_struct;
}
class MyClass : public MyBaseClass {
public:
MyClass( XML cfg ) { m_struct = MyStruct( cfg ); }
}
Now the compiler is complaining that MyStruct does not have an empty constructor
error: no matching function for call to ‘MyStruct::MyStruct()’
MyClass( XML cfg ) { m_struct = MyStruct( cfg ); }
I dont think teh inheritance plays a role ehre, but I kept it for completeness as it may be the case. I never explicitly call an empty constructor for MyStruct. Does the class MyClass do that because m_struct is its member?
If that is teh case, is there a way to not have it initialize the member or is this only possible with pointers as members?
I am aware I can fix this by just adding an empty constructor to my structure or by changing the constructor to
MyClass( XML cfg ) : m_struct = MyStruct( cfg ) {}
but I am curious to know what exactly is going on here.