Hi All,

can any of u explain the order of constructors ,how it will behaves when order of derived classes as like present in attachment

>can any of u explain the order of constructors
It's in the order of declaration, from base classes to derived classes. Take B1, B2, and V2. The diagram doesn't (and can't) specify whether B1 or B2 is called first because that would depend on the declaration order. This will print "B1, B2, V2" because B1 is declared before B2 in V2's definition:

#include <iostream>

class B1 {
public:
    B1() { std::cout<<"B1, "; }
};

class B2 {
public:
    B2() { std::cout<<"B2, "; }
};

class V2: public B1, public B2 {
public:
    V2() { std::cout<<"V2\n"; }
};

int main()
{
    V2 v;
}

But this will print "B2, B1, V2" because B1 and B2 are switched such that B2 is declared before B1 in V2's definition:

#include <iostream>

class B1 {
public:
    B1() { std::cout<<"B1, "; }
};

class B2 {
public:
    B2() { std::cout<<"B2, "; }
};

class V2: public B2, public B1 {
public:
    V2() { std::cout<<"V2\n"; }
};

int main()
{
    V2 v;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.