Bài giảng lập trình hướng đối tượng virtual method và polymorphism trần phước tuấn

12 148 0
Bài giảng lập trình hướng đối tượng virtual method và polymorphism   trần phước tuấn

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

N i dung L P TRÌNH NG IT NG VIRTUAL METHOD & POLYMORPHISM Tr n Ph c Tu n tuantp@hcmup.edu.vn http://giaotrinh.tranphuoctuan.com i k t t nh (Static binding) i k t ng (Dynamic binding) Ch y ch ng trình Bài toán th c t Ph ng th c o, a hình Ph ng th c h y b o Ph ng th c thu n o, l p tr u t 9/6/2009 Static binding TPTU N - LTH T 2 Dynamic binding class Circle { int x,y,r; public: Circle (int xx, int yy, int rr) { x=xx; y=yy; r=rr; } void print() { cout [...]... Summary Virtual Method is a way to make polymorphism Syntax for virtual method: virtual ReturnType Method (parameters) ReturnType virtual Method (parameters) Compiler will determine the right method will be called using a virtual function table for every class which contains virtual methods Pure virtual method is a virtual method but it has no code Syntax for pure virtual method: virtual ReturnType Method. .. code Syntax for pure virtual method: virtual ReturnType Method (parameters)=0; TPTU N - LTH T 9/6/2009 45 Abstract class is a result of so-high generation Abstract class must have at least one pure virtual method You can not create an object of abstract class but you can declare a pointer to it then, it points to an object of a concrete subclass 9/6/2009 TPTU N - LTH T 46 9/6/2009 TPTU N - LTH T 48 Exercises ... 43 9/6/2009 TPTU N - LTH T 44 Summary Summary Virtual Method is a way to make polymorphism Syntax for virtual method: virtual ReturnType Method (parameters) ReturnType virtual Method (parameters)... right method will be called using a virtual function table for every class which contains virtual methods Pure virtual method is a virtual method but it has no code Syntax for pure virtual method: ... ch Ch y ch ng trình ng trình Polymorphism ability occurs only when you use a pointer to an object and used-methods of classes are virtual methods virtual ReturnType or ReturnType virtual are accepted

Ngày đăng: 03/01/2016, 10:22

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan