virtbase.cpp
710 Bytes
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
#include <iostream>
using namespace std;
class A
{ // no constructor
// ...
};
class B
{
public:
B (){cout<<"B::B()"<<endl;}// default constructor
// ...
};
class C
{
public:
C (int){cout<<"C::C(int)"<<endl;}; // no default constructor
};
class D: virtual public A, virtual public B, virtual public C
{
public:
#ifndef ERROR
D ():C(15) {cout<<"D::D()"<<endl;}; // ok
#else
D ():{/* ... */}; // error: no default constructor for C
#endif
D (int i):C (i) {/* ... */};// ok
// ...
};
class E: public D
{
public:
#ifdef ERROR
E () {/* ... */}; // error: no default constructor for C
#endif
E (int i):C (i) {cout<<"E::E(int)"<<endl;}; // ok
// ...
};
int main()
{
D d(3);
E e(4);
}