-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtut55.cpp
More file actions
40 lines (37 loc) · 930 Bytes
/
Copy pathtut55.cpp
File metadata and controls
40 lines (37 loc) · 930 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
#include <iostream>
using namespace std;
class base
{
public:
int var_base;
void display()
{
cout << "Displaying the variable of the base classes: " << var_base << endl;
}
};
class derived : public base
{
public:
int var_derived;
void display()
{
cout << "Displaying the variable of the Base classes: " << var_base<< endl;
cout << "Displaying the variable of the derived classes: " << var_derived << endl;
}
};
int main()
{
base *base_point;
base obj_base;
derived obj_derived;
base_point = &obj_derived; // Pointing base class pointer to derived class
base_point->var_base = 44;
// base_point->var_derived = 144; // will throw an error
base_point->display();
derived * derived_point ;
derived_point = &obj_derived;
derived_point->var_base = 4644;
derived_point->var_derived = 990;
derived_point->display();
return 0;
}