CS246 Lecture Notes - Lecture 20: Compile Time, Bridge Pattern, Virtual Function

36 views3 pages

Document Summary

November 19 visitor design pattern, compilation dependencies, bridge pattern. // strike enemy with weapon e->strike(&w); // strike, virtual method w->useon(&e); E->strike, w->useon only single dispatch, not dynamic class enemy{ public: virutal void strike(weapon &w) = 0; class turtle : public enemy{ public: void strike(weapon &w){ w. useon(*this); } // compile time, *this is known to be a turtle class bullet : public enemy{ public: void strike(weapon &w){ w. useon(*this); } Override dynamic dispatch, override behaviour in subclasses. Benefit 1: double dispatch: choosing a method based on the runtime type of 2 objects. Book by author textbook by topic author > # topic > # (string) (int) (string) (int) map catalog; #define alist_h class blist; class alist{ int data; #define blist_h class alist; class blist{ char data; #endif a. h class a { }; b. h. A mya; d. h class a; class d{ a *mya; }; e. h class a; class e{ Include when you need to know the size.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents