C
cppaddict
If you have a class with:
1. Many members
2. Two or more constructors
and if you follow the C++ FAQ guidelines of initializing all member
variables in a contructor initialiazation list, then you might have
two constructors that repeat much of the same code:
MyClass() :
_member1(0),
_member2(0),
_member3("default string")
_member4(0.0)
...etc...
{}
MyClass(int x, int y) :
_member1(0),
_member2(0),
_member3("default string")
_member4(0.0)
...etc...
{
// does some stuff with x and y
}
How can you avoid this unnecessary repetition?
Thanks for any ideas,
cpp
1. Many members
2. Two or more constructors
and if you follow the C++ FAQ guidelines of initializing all member
variables in a contructor initialiazation list, then you might have
two constructors that repeat much of the same code:
MyClass() :
_member1(0),
_member2(0),
_member3("default string")
_member4(0.0)
...etc...
{}
MyClass(int x, int y) :
_member1(0),
_member2(0),
_member3("default string")
_member4(0.0)
...etc...
{
// does some stuff with x and y
}
How can you avoid this unnecessary repetition?
Thanks for any ideas,
cpp