-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinheritance.cpp
executable file
·48 lines (38 loc) · 983 Bytes
/
inheritance.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
41
42
43
44
45
46
47
48
#include <iostream>
class Person
{
std::string m_Name;
int m_Age;
public:
Person(std::string, int);
void showPersonInfo();
// std::string getName() { return m_Name; }
// int getAge() { return m_Age; }
};
Person::Person(std::string name, int age) : m_Name(name), m_Age(age){};
void Person::showPersonInfo()
{
std::cout << "Name: " << m_Name << std::endl;
std::cout << "Age: " << m_Age << std::endl;
}
class Student : public Person
{
int m_StudentId;
public:
Student(std::string, int, int);
void showStuedentInfo()
{
showPersonInfo();
std::cout << "Student ID: " << m_StudentId << std::endl;
}
};
Student::Student(std::string name, int age, int id) : Person(name, age), m_StudentId(id){};
int main()
{
Person p("Asraful", 23);
Student s("Taj", 20, 21201627);
p.showPersonInfo();
std::cout << std::endl;
s.showStuedentInfo();
return 0;
}