Open Source Your Knowledge, Become a Contributor
Technology knowledge has to be shared and made accessible for free. Join the movement.
description:
4 times. Virtual inheritance affects the class that is inherited virtually. Therefore the BS base class is not inherited virtually and there are 4 of them within 1 DR object. The virtual inheritance statements in this code are affecting the classes mid1, mid2, mid3, mid4 and not BS.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
struct BS
{
BS()
{
std::cout << "Hello World" << std::endl;
}
};
struct mid1 : public BS { };
struct mid2 : public BS { };
struct mid3 : public BS { };
struct mid4 : public BS { };
struct DR : public virtual mid1, public virtual mid2, public virtual mid3, public mid4 { };
int main(int argc, char** argv)
{
DR d;
return 0;
}
Enter to Rename, Shift+Enter to Preview
Open Source Your Knowledge: become a Contributor and help others learn. Create New Content