No. (not that way anyway)
You might be mislead by the way things are done in other languages like Java, C#, ActionScript, etc.
In C++, multiple inheritance and the way virtual classes are managed makes interfaces (as used in other languages) obsolete. In those other languages, interfaces are used to fix problems issued from the lack of multiple inheritance (good or bad, it's a choice).
So if what you want to do is just provide a general interface with some virtual methods providing default implementations, just implement in the base class :
class Interface
{
virtual void myfunction() { /*...*/ } ; //default implementation
virtual void yourFunction() = 0 ; // this one HAVE TO be implemented by the user
}
class Derived
: public public Interface // dont' need another clas
{
// myfunction is implemented by base
void yourFunction(); // have to implement yourFunction
}
class DerivedB
: public public Interface // dont' need another clas
{
void myFunction();// myfunction is implemented by base but we implement it for this specific class
void yourFunction(); // have to implement yourFunction
}
If however, you want to provide several base classes that have the same interfaces, then think that your interface class is the bases of the other classes
// in this order
class Interface
{
virtual void myfunction() = 0;
}
class BaseA : public Interface
{
// here "virtual" is optional as if the parent is virtual, the child is virtual too
virtual void myfunction() {/*...*/}; // BaseA specific implementation
}
class BaseB : public Interface
{
virtual void myfunction() {/*...*/}; // BaseB specific implementation
}
There is however a not-really-easy-to-read (read: not recommanded) way to provide a default implementation BUT forcing the user to explicitely say if he want to use it or not. It exploit the fact that even pure virtual functions can have default implementations that can be called :
class Interface
{
virtual void myfunction() { /*...*/ } ; //default implementation
virtual void yourFunction() = 0 ; // this one HAVE TO be implemented by the user BUT provide a default implementation!
}
// in Interface.cpp
void Interface::yourFunction() // default implementation of the virtual pure function
{ /*...*/ }
// in Derived.h
class DerivedA
: public public Interface // dont' need another clas
{
// myfunction is implemented by base
void yourFunction(); // have to implement yourFunction -- DerivedA specific
}
class DerivedB
: public public Interface // dont' need another clas
{
void myFunction();// myfunction is implemented by base but we implement it for this specific class
void yourFunction() { Interface::yourFunction(); } // uses default implementation of yourFunction, hidden but existing
}
But don't do it.