implicit call to constructor

Can anyone help me with the question???

If a class D inherits two base classes B1 and B2 ,then write these classes containing no-argument constructors those simply display the names of the respective classes. Instantiate an object of class D ensuring that first it implicitly creates the object of class B2 and then it implicitly creates the object of class B1 for its use.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>

struct B1
{
   B1() { std::cout << "B1::B1()\n"; }
};

struct B2
{
   B2() { std::cout << "B2::B2()\n"; }
};

struct D : B2, B1
{
   D() { std::cout << "D::D()\n"; }
};

int main()
{
   D d;
}
Last edited on
Topic archived. No new replies allowed.