用template实现的Adapter
class Class1 { public: Class1(int c) : m_count(c) { PRINT; } void proc() { PRINT; } private: int m_count; }; class Class2 { public: Class2(const string& name): m_name(name) { PRINT; } void proc() { PRINT; } private: string m_name; }; class IAdapter { public: virtual ~IAdapter() {} virtual void proc() = 0; }; template<typename T> class Adapter: public IAdapter, private T { public: Adapter(int c): T(c) { PRINT; } Adapter(const string& name) :T(name) { PRINT; } void proc() { T::proc(); } };