When there is the same function declare name in the two interfaces, for example, Interface IA {Virtual Void Fun () = 0;}; interface ib {virtual void fun () = 0;
Class CD inherited these two interfaces: Class CD: Public Ia, Public IB {public: void fun ();
If this effect is to be achieved: there is a different implementation for the interface function FUN of IA and IB, which involves the problem of multiple inheritance functions.
Classic solution is the introduction middle class proposed in ARM: Class IAIMPL: Public IA {public: Virtual Void Fun () {internalFuna ();
Virtual void infrinkler () = 0;
Class ibimpl: public ip {public: Virtual void fun () {internalfunb ();
Virtual void infrinklefunb () = 0;
The current Class CD should be this Class CD: Public IAIMPL, PUBLIC IBIMPL {public: void infuna () {// Here IA :: Fun ()} void infunb () {// Implement IB :: fun () }};
In this way, the same name function problem with multiple inheritance is successfully solved, where the FUN function in IAIMPL and IBIMPL uses the simplest template method mode.
Of course, this is used here, which can be replaced with a template. The more efficient solution is as follows: Template
Template
Class CD: Public IAIMPL
This avoids the overhead of the virtual function call.