I\'m sure this is a really simple question. The following code shows what I\'m trying to do:
class MemberClass {
public:
MemberClass(int abc){ }
};
clas
Use the initializer list syntax:
class MyClass {
public:
MemberClass m_class;
MyClass(int xyz) : m_class(xyz == 42 ? MemberClass(12) : MemberClass(32)
/* see the comments, cleaner as xyz == 42 ? 12 : 32*/)
{ }
};
Probably cleaner with a factory:
MemberClass create_member(int x){
if(xyz == 42)
return MemberClass(12);
// ...
}
//...
MyClass(int xyz) : m_class(create_member(xyz))