samedi 14 décembre 2019

Chained Converting Constructors

class A{
public:
    A(int i){}
};
class B{
public:
    B(A){}
};
void test(B){};
int main() {
    A a=1;
    B b1=a;
    test(1);
}

I have two classes, where the first class has a converting int Ctor, which means that I can construct it by "assigning" an integer (first line).

The second class has a converting Ctor with argument type A. It is possible to construct b1 with a (second line).

Is there any possibility to use multiple converting ctor in a chain, in such a way that the third row will compile?

Aucun commentaire:

Enregistrer un commentaire