How to create one object with two or more constructor initialization

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

valuation O(v) // ?
valuation O(a,b,c); // ?
}

Thanks
Last edited on
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(const int s): valuation(s, 0, 0, 0){}
    valuation(int a, int b, int c): valuation(0, a, b, c){}

private:
    const int pos;
    int j, k, l;

    valuation(int s, int a, int b, int c): pos(s), j(a), k(b), l(c){}
}
The second constructor (one that takes three int arguments) would generate a compile-time error;
it dos not initialise the const member 'pos'
Thank @helios
This looks like followup to: http://www.cplusplus.com/forum/general/264431/

@abdulbadii:
Do note that the example by helios produces:
1
2
3
4
int a=1, b=2, c=3, v=7;

valuation X(v);     // X.pos=7 X.j=0 X.k=0 X.l=0
valuation Y(a,b,c); // Y.pos=0 Y.j=1 Y.k=2 Y.l=3 
Topic archived. No new replies allowed.