Can not identify error

What can I do if I want to solve these errors after compiling this code without defining new constructor for any class .The given constructor for each class must take only one integer calue as a parameter except A!'s default constructor.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
  #include <iostream>

using namespace std;

class A1
{
public:
    A1(int x)
    {
        cout<<"A1:: A1(int) called"<<endl;
    }
};
class A2:public A1
{
public:
    A2(int x)
    {
        cout<<"A2:: A2(int) called"<<endl;
    }
};
class A3:public A1
{
public:
    A3(int x)
    {
        cout<<"A3:: A3(int) called"<<endl;
    }
};
class A4:virtual public A2
{
public:
    A4(int x)
    {
        cout<<"A4:: A4(int) called"<<endl;
    }
};
class A5:virtual public A3
{
public:
    A5(int x)
    {
        cout<<"A5:: A5(int) called"<<endl;
    }
};
class A6:public A4,public A5
{
public:
    A6(int x)
    {
        cout<<"A6:: A6(int) called"<<endl;
    }
};

int main()
{
    A6 a61(60);
    return 0;
}
By default the derived class constructors will call the default base class constructor. If you want it to call another constructor you need to explicitly specify by listing the constructor in the constructor initialization list.

1
2
3
4
5
6
7
8
9
class A2 : public A1
{
public:
	A2(int x)
	:	A1(x)
	{
		cout<<"A2:: A2(int) called"<<endl;
	}
};
Last edited on
Topic archived. No new replies allowed.