When we use some of the groups of others, it is likely that this group is written in writing. Although they are related in the concept of reality. And these classes may have some ways to use the same form of functions, just that we are often used. Then use these classes when using these classes, if you need to obtain the pointer to the instance, call the corresponding function, you must make your own judgment type. But you can use the way to add an interface to implement more easily.
// Objective: Adding an interface for unwritten non-dry classes. // Method: The original class is re-packaged once, which has the original behavior and data simultaneously with an interface.
Class T1 {INT I; Public: Void Set (INT i) {i = i;}; void show () {cout << "this is t1: << i << endl;};
Class T2 {INT I; PUBLIC: VOID SET (INT i) {i = i * 2;}; void show () {cout << "this is t2: << << {{Endl;};
// T1 and T2 are two unconcerable classes, but have the same form of member function. / Defines an interface class
Class interface {public: Virtual void set (int) = 0; virtual void show () = 0; virtual ~ interface () {};
// Package the original class interface Class Packt1: Virtual Public Interfacet, T1 {public: Void Set (INT i) {T1 :: Set (i);}; void show () {t1 :: show (); ;}; Class Packt2: Virtual public interface, t2 {public: void set (INT i) {t2 :: set (i);}; void show () {t2 :: show ();};
You can generate an instance with the PackT1 and PackT2 class, which has the original T1 and T2 behavior data, and can be accessed with interface pointers.
For example: PackT1 T1; IT = & T1; IT-> set (5); it-> show (); it = & t2; it-> show ();