Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Hierarchy of Inheritance, Classes, Inheritance relation, Tree like hierarchy, Direct Base Class, Indirect Base Class, Base Initialization, Initialization list are points you can learn in this Object Oriented Programming lecture.
Typology: Slides
1 / 24
GrandParent
Parent1 Parent
Child1 (^) Child
class Child1:public Parent
...
class GrandParent{}; class Parent1: public GrandParent {}; class Child1:public Parent1{};
class GrandParent{
int gpData;
public:
GrandParent() : gpData(0){...} GrandParent(int i) : gpData(i){...} void Print() const;
};
class Parent1: public GrandParent{
int pData;
public:
Parent1() : GrandParent(), pData(0) {…}
};
class Child1 : public Parent1 {
public:
Child1() : Parent1() {...} Child1(int i) : GrandParent (i) //Error {...} void Print() const;
};
GrandParent Print()
Parent
Child Print()
void GrandParent::Print() {
cout << “GrandParent::Print” << endl;
}
void Child1::Print() {
cout << “Child1::Print” << endl;
}
int main(){
Child1 obj; obj.Print(); obj.Parent1::Print(); obj.GrandParent::Print(); return 0;
}
Child1::Print
GrandParent::Print
GrandParent::Print
Base Class Derived Class
Public Public
Protected Protected
Private Hidden
class Child: public Parent {…};
Base Class Derived Class
Public Protected
Protected Protected
Private Hidden
class Child: protected Parent {…};
Base Class Derived Class
Public Private
Protected Private
Private Hidden
class Child: private Parent {…};
class Child: private Parent {…}
is equivalent to
class Child: Parent {…}
class Collection {
...
public:
void AddElement(int); bool SearchElement(int); bool SearchElementAgain(int); bool DeleteElement(int);
};
class Set: private Collection {
private:
...
public:
void AddMember(int); bool IsMember(int); bool DeleteMember(int);
};
void Set::AddMember(int i){
if (! IsMember(i) ) AddElement(i);
}
bool Set::IsMember(int i){
return SearchElement(i);
}