kkenny@wind.nrtc.northrop.com (Kevin B. Kenny KE9TV) (10/25/90)
In Bjarne Stroustrup's paper, ``Multiple Inheritance for C++,'' Stroustrup discusses an extension of the inheritance mechanism that allows a class to inherit froman object identified by pointer: i.e., ------------------------------------------------------------------------ class B { int b; void f (); }; class C : public *p { private: B* p; public: C () : p (new B) {}; C (B* q) : p (q) {}; } void f (C* q) { q -> f (); // that is, q -> p -> f (); } ------------------------------------------------------------------------ This extension never made it into the language. I'm curious what its status is: were there insuperable problems with it? What other way is provided for the designer of a class B to specify that B wants to inherit from A *or from any of A's derived classes*? Kevin Kenny KE9TV Northrop Research & Technology Center Opinions expressed in this article are those of the author, and not official positions of Northrop Corporation or any of its subsidiaries.
gordon@meaddata.com (Gordon Edwards) (10/25/90)
In article <11578@gremlin.nrtc.northrop.com>, kkenny@wind.nrtc.northrop.com (Kevin B. Kenny KE9TV) writes: |> |> In Bjarne Stroustrup's paper, ``Multiple Inheritance for C++,'' |> Stroustrup discusses an extension of the inheritance mechanism that |> allows a class to inherit froman object identified by pointer: i.e., |> [example deleted. -gordon] |> |> This extension never made it into the language. I'm curious what its |> status is: were there insuperable problems with it? What other way is |> provided for the designer of a class B to specify that B wants to |> inherit from A *or from any of A's derived classes*? |> C++ supports a limited form of delegation. Operations can be forwarded to delegate objects. The following examples were taken from a pilot of AT&T's "Object Oriented Design for C++", that I attended during the summer. class Employee { ... void SortMail(Mail); void SignVouchers(Vouchers); ... }; class Manager { Employee* maildelegate; Employee* voucherdelegate; public: void sortMail(Mail); void signVouchers(Vouchers); Manager(Employee* mailsorter = 0, Employee* vouchersigner = 0); }; Manager::Manager(Employee* mailsorter, Employee* vouchersigner) { maildelegate = mailsorter; voucherdelegate = vouchersigner; } void Manager::sortMail(Mail m) { if (maildelegate) maildelegate->sortMail(m); } void Manager::signVouchers(Vouchers v) { if (voucherdelegate) voucherdelegate->signVouchers(v); } This concept can be extended to dynamically change the delegated operation. E-mail me if your interested. Delegation (limited) in this fashion reduces code readability and the program structure is moved into run-time structure. It does, however, increase flexibility and can be combined "tastefully" with inheritance. -- Gordon (gordon@meaddata.com)