How can I simulate interfaces in C++?

后端 未结 9 2122
时光说笑
时光说笑 2020-12-04 19:22

Since C++ lacks the interface feature of Java and C#, what is the preferred way to simulate interfaces in C++ classes? My guess would be multiple inheritance o

9条回答
  •  臣服心动
    2020-12-04 20:18

    By the way MSVC 2008 has __interface keyword.

    A Visual C++ interface can be defined as follows: 
    
     - Can inherit from zero or more base
       interfaces.
     - Cannot inherit from a base class.
     - Can only contain public, pure virtual
       methods.
     - Cannot contain constructors,
       destructors, or operators.
     - Cannot contain static methods.
     - Cannot contain data members;
       properties are allowed.
    

    This feature is Microsoft Specific. Caution: __interface has no virtual destructor that is required if you delete objects by its interface pointers.

提交回复
热议问题