Skip to content

Commit bcaa0ed

Browse files
author
sajith
committed
Improved
1 parent 1a11820 commit bcaa0ed

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ set(CMAKE_CXX_STANDARD 20)
2424
#add_executable(isp_door_better ISP/isp_door_example_better.cpp)
2525
#add_executable(isp_door_better2 ISP/isp_door_example_better2.cpp)
2626
#add_executable(isp_device ISP/isp_device_example.cpp)
27-
add_executable(isp_device_better ISP/isp_device_example_better.cpp)
27+
#add_executable(isp_device_better ISP/isp_device_example_better.cpp)
28+
add_executable(isp_multiple_inheritance ISP/isp_multiple_inheritance.cpp)

ISP/isp_multiple_inheritance.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//
2+
// Created by sajith on 4/20/21.
3+
//
4+
5+
#include <iostream>
6+
#include <memory>
7+
8+
class A
9+
{
10+
public:
11+
virtual ~A() = default;
12+
13+
virtual void foo()
14+
{
15+
std::cout << "A\n";
16+
}
17+
};
18+
19+
20+
class B : public virtual A
21+
{
22+
public:
23+
void foo()
24+
{
25+
std::cout << "B\n";
26+
}
27+
};
28+
29+
30+
class C : public virtual A
31+
{
32+
public:
33+
void foo()
34+
{
35+
std::cout << "C\n";
36+
}
37+
};
38+
39+
40+
class D : public B, public C
41+
{
42+
public:
43+
void foo()
44+
{
45+
std::cout << "D\n";
46+
}
47+
};
48+
49+
// Diamond problem
50+
/*
51+
/\
52+
\/
53+
*/
54+
55+
int main()
56+
{
57+
std::unique_ptr<A> p = std::make_unique<D>();
58+
p->foo();
59+
60+
return 0;
61+
}

0 commit comments

Comments
 (0)