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
Class Collection, Class Set, Private Collection, Specialization Restriction, Derived class, Base class, Private and protected inheritance, Member functions, Friend functions are points you can learn in this Object Oriented Programming lecture.
Typology: Slides
1 / 29
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);
};
Person age : [0..125]
Adult age : [18..125]
setAge( a )
setAge( a )
age = a
If age < 18 then error else age = a
class Person{ … protected: int age; public: bool SetAge(int _age){ if (_age >=0 && _age <= 125) { age = _age; return true; } return false; } }; Docsity.com
class Adult : private Person { public: bool SetAge(int _age){ if (_age >=18 && _age <= 125) { age = _age; return true; } return false; } };
class Parent{ }; class Child : private Parent{ };
int main(){ Child cobj; Parent *pptr = & cobj; //Error return 0; }
void DoSomething(const Parent &);
Child::Child(){
Parent & pPtr = static_cast<Parent &>(this); DoSomething(pPtr); // DoSomething(this);
}
class Parent{ public: Parent(){ cout << “Parent Constructor”; }
Parent(const Parent & prhs){ cout << “Parent Copy Constructor”; } };
class Child: private Parent{ public: Child(){ cout << “Child Constructor”; } Child(const Child & crhs) :Parent(crhs){ cout << “Child Copy Constructor”; } };
int main() {
Child cobj1; Child cobj2 = cobj1; //Child cobj2(cobj1); return 0;
}
Parent Constructor Child Constructor Parent Copy Constructor Child Copy Constructor
class GrandParent{ public : void DoSomething(); };
class Parent: private GrandParent{ void SomeFunction(){ DoSomething(); } };
class Child: private Parent
{
public:
Child() { DoSomething(); //Error }
};
void DoSomething(GrandParent&);
class GrandParent{
};
class Parent: private GrandParent{
public:
Parent() {DoSomething(*this);}
};
class Child: private Parent {
public:
Child() { DoSomething(*this); //Error }
};
class GrandParent{ public : void DoSomething(); };
class Parent: protected GrandParent{ void SomeFunction(){ DoSomething(); } };