Interfaces in C++

Unlike Java and C#, C++ doesn’t have a distinct interface type. However, you can define an interface as an abstract base class with only pure virtual functions.
You need a virtual destructor, which you can make empty rather than pure virtual so that classes that implement your interface only need to add their own if they really need one (if they manage any state that needs to be released on destruction).
Similarly, the interface methods can be made optional by giving them an empty implementation. The version of the optional method in the interface class can throw an exception like Java’s UnsupportedOperationException if merely doing nothing isn’t acceptable.

class IMyInterface
{
    virtual ~IMyInterface()
    {
    }
    virtual void Method1() = 0;  // Must be implemented
    virtual void Method2() {}  // Optional
};