TAILIEUCHUNG - Object Oriented Programming (14)

CSC241: Object Oriented Programming. Lecture No 14. 1 Previous Lecture.•. Protected members.•. Generalization in UML representation. class.•. Example program class. A A(). ~A(). Counter. A {}. –. ~A() { {}. A() { }. – CountDn }. class. A a1; class ~B(. C *c1 = new B B().•. Derived class B ). C; ~B() { {}. – Constructor B b1; B() { } {}. }. class. – Destructor delete c1; class ~C(. C c1; C C(). C ). {}.•. Function overriding ~C() { {}. C() { }. } 2 Today’s Lecture.•. Function overriding. – Example program – Distance class.•. Class hierarchy. – Employee program.•. Public and private Inheritance.•. Level of inheritance. 3 Overriding Member Functions.•. Member functions in a derived class can be. override, . have the same name as those. in the base class.•. Stack, a simple data storage medium. It. allowed you to push integers onto the stack. and pop them off. class A. abc(int x) { } class B. abc(int x) { }. 4class Stack {. protected: Example - stack. int st[3];. int top; class Stack2 : public Stack{. public: public:. Stack() void push(int var1){. { top = -1; } S1 if(top >= 3 -1){. void push(int var) {. st[++top] = var;. cout << “\nError: stack is. } full”;. int pop() { exit(1);. return st[top--]; top }. } Stack::push(var);.}; -1. 02. 1 }. st[3] int pop() {. Stack2 s1;. (11); 1 if(top < 0) {. cout << “\nError: stack is. (22); 3. 1 empty”;. (33);. cout <<();. exit(1);. cout <<();. cout <<();. 2 }. cout <<();. 11 returnGo to program. Stack::pop(); 5 Which function is called?.•. (11); Which function is executed? Derive. or Base class.•. Rule: When the same function exists in both the. base class and the derived class, the function in. the derived class will be executed.•. This is true for objects of the derived class.•. Objects of the base class don’t know anything. abou

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.