-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path001 Ad Hoc Polymorphism.cpp
40 lines (35 loc) · 1.14 KB
/
001 Ad Hoc Polymorphism.cpp
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
/***
* Ad Hoc Polymorphism
* Adhoc describes how the methods of one class will act after their inheritance to another class.
* Most known 5 types of methods that base on the Ad-hoc definition
virtual void AbstractMethod();
void RegularMethod() { }
void NewMethod() { }
virtual void VirtualMethod() { }
void OverridedMethod override () { }
*/
#include <iostream>
class Base
{
public:
virtual void AbstructMethod() = 0; // no implementation
void RegularMethod() { std::cout << "Regular Method - Base\n"; }
virtual void VirtualMethod() { std::cout << "Virtual Method - Base\n"; }
public:
virtual ~Base() = default;
};
class Derive : public Base
{
public:
void AbstructMethod() { std::cout << "Abstruct Method implementation - Derive\n"; }
void RegularMethod() { std::cout << "New implementation - Regular Method - Derive\n"; }
void VirtualMethod() override { std::cout << "Virtua Method Override - Derive\n"; }
};
int main()
{
Base* basic = new Derive();
basic->AbstructMethod(); // Abstruct Method implementation - Derive
basic->RegularMethod(); // Regular Method - Base
basic->VirtualMethod(); // Virtua Method Override - Derive
delete basic;
}