Object Oriented Programming Inheritance based on faculty washington
Object Oriented Programming Inheritance ירושה based on: faculty. washington. edu/jkp/CPP/Intro/lectures/inherit. ppt http: //msdn. microsoft. com/en-us/library/a 48 h 1 tew(v=vs. 100). aspx 1 . © כל הזכויות שמורות. נכתב ע"י יעל ארז
ירושה A printed document is a kind of document A book is a kind of printed document A help file is a kind of online document … מבוא Document Online document Printed document Book Help file Online tutorial Magazine -5 - . © כל הזכויות שמורות. נכתב ע"י יעל ארז
ירושה הכללה צמצום מבוא Class Instance Document my document Printed document My printed document Book Magazine -7 - BVD war. And. Peace . © כל הזכויות שמורות. נכתב ע"י יעל ארז
ירושה Single inheritance Base Class Derived Class Document אבא Printed document ילד -8 - . © כל הזכויות שמורות. נכתב ע"י יעל ארז
ירושה Single Inheritance Indirect Base Class Document Direct Base Class Printed document אבא Derived Class Book ילד -9 - . © כל הזכויות שמורות. נכתב ע"י יעל ארז
ירושה class Printed. Document {}; // Book is derived from Printed. Document. class Book : public Printed. Document {}; // Paperback. Book is derived from Book. class Paperback. Book : public Book {}; Copyright 2006 Oxford Consulting, Ltd - 10 - 1 February 2006
ירושה Multiple Inheritance animal mamal winged animal bat - 11 - . © כל הזכויות שמורות. נכתב ע"י יעל ארז
ירושה Multiple Inheritance : משותף אבא ללא לרשת גם ניתן person employee teacher http: //upload. wikimedia. org/wikipedia/en/1 /1 f/Spider-Man-Comics-Weekly 01. jpg - 12 - . © כל הזכויות שמורות. נכתב ע"י יעל ארז
ירושה class Stack stack_1. cpp { protected: int size ; // max Number of elements on Stack int top ; // index of last entered element int* s ; public: Stack(int = 10) ; ~Stack() { delete [] s ; } int push(int); int pop(int&) ; // pop an element off the stack int is. Empty()const { return top == -1 ; } int is. Full() const { return top == size - 1 ; } - 17 } ; דוגמא . © כל הזכויות שמורות. נכתב ע"י יעל ארז
סוגי ירושה class base{ …. class base definition }; class derived 1 : public base{ …class derived 1 definition; }; class derived 2 : protected base{ …class derived 2 definition; }; class derived 3 : private base{ …class derived 3 definition; }; public ירושת protected ירושת private ירושת - 18 - . © כל הזכויות שמורות. נכתב ע"י יעל ארז
סוגי ירושה public ירושת class A { public: int x; protected: int y; private: int z; }; class B : public A { // x is public // y is protected // z is not accessible from B }; - 19 - . © כל הזכויות שמורות. נכתב ע"י יעל ארז
סוגי ירושה protected ירושת class A { public: int x; protected: int y; private: int z; }; class C : protected A { // x is protected // y is protected // z is not accessible from B }; - 20 - . © כל הזכויות שמורות. נכתב ע"י יעל ארז
סוגי ירושה private ירושת class A { public: int x; protected: int y; private: int z; }; class D : private A { // x is private // y is private // z is not accessible from B }; - 21 - . © כל הזכויות שמורות. נכתב ע"י יעל ארז
- Slides: 24