Now, I know it is generally bad to add new virtual functions to non-leaf classes as it breaks binary compatibility for any derived classes which haven't been recompiled. However, I have a slightly different situation:
I have an interface class and implementation class compiled into a shared library, for example:
class Interface {
public:
static Interface* giveMeImplPtr();
...
virtual void Foo( uint16_t arg ) = 0;
...
}
class Impl {
public:
...
void Foo( uint16_t arg );
....
}
My main application uses this shared library, and could basically be written as:
Interface* foo = Implementation::giveMeImplPtr();
foo->Foo( 0xff );
In other words, the application doesn't have any classes which derive from Interface
, it merely uses it.
Now, say I want to overload Foo( uint16_t arg )
with Foo( uint32_t arg )
, am I safe to do:
class Interface {
public:
static Interface* giveMeImplPtr();
...
virtual void Foo( uint16_t arg ) = 0;
virtual void Foo( uint32_t arg ) = 0;
...
}
and recompile my shared library without having to recompile the application?
If so, are there any unusual caveats I need to be aware of? If not, do I have any other options other than to take the hit and up-version the library, thus breaking backwards compatibility?