How do we create one object with two or more constructor initialization at once,
without changing any of all overload constructors and other existing codes? (Or if not at all, as the least change as possible)
class valuation {
public:
valuation(const int s) : pos(s) {};
valuation(int a,int b,int c) : j(a),k(b),l(c) {};
private:
const int pos;
int j,k,l;
}
main(){
int a=1,b=2,c=3, v=7;
// how to set pos=7 j=1 k=2 l=3 once below just illustration
I'm not sure I understand, but I think you're asking how to reuse a constructor's initialization list to avoid repeating the same initializations in every constructor.
For example, you could do
1 2 3 4 5 6 7 8 9 10 11
class valuation {
public:
valuation(constint s): valuation(s, 0, 0, 0){}
valuation(int a, int b, int c): valuation(0, a, b, c){}
private:
constint pos;
int j, k, l;
valuation(int s, int a, int b, int c): pos(s), j(a), k(b), l(c){}
}