-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathderived.cc
More file actions
50 lines (40 loc) · 760 Bytes
/
derived.cc
File metadata and controls
50 lines (40 loc) · 760 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
45
46
47
48
49
50
#include <iostream>
#include <string>
using namespace std;
class base
{
public:
virtual void display(int i = 10)
{
cout<<"Base class display with i = "<<i<<endl;
}
};
class A
{
int c;
public:
A() : c(111) {}
void show()
{
cout << "c value is : " << c << endl;
}
};
class derived : public base, public A
{
public:
void display(int i)
{
cout<<"Derived class display with i = "<< i <<endl;
}
};
int main(int argc, char *argv[])
{
base *bptr = new derived;
bptr->display();
derived d;
base* pbase = &d;
A* a = dynamic_cast<A*>(pbase);
cout << "Pointer value is: " << (a != NULL ? 1: 0) << endl;
a->show();
return 0;
}