I have class D
inherited from B
:
struct D: public B {
D(int b1, int p);
D(int b1, int b2, int p);
int p1;
float p2;
double p3;
std::string p4;
};
Contructors code is the same except base class intilization:
D::D(int b1, int p): B(b1)
, p1(p)
, p2(SomeFunc())
, p3(SomeOtherFunc() - 42)
, p4("abc")
{}
D::D(int b1, int b2, int p): B(b1, b2)
, p1(p)
, p2(SomeFunc())
, p3(SomeOtherFunc() - 42)
, p4("abc")
{}
The question: is there any way to make the code more compact and less "copy-pasted"?