现在,我知道向非叶类添加新的虚函数通常是不好的,因为它会破坏任何派生类的二进制兼容性,而这些类没有被重新编译。但是,我有一个稍微不同的情况:纯虚函数和二进制兼容性
我编译成一个共享库的接口类和实现类,例如:
class Interface {
public:
static Interface* giveMeImplPtr();
...
virtual void Foo(uint16_t arg) = 0;
...
}
class Impl {
public:
...
void Foo(uint16_t arg);
....
}
我主要的应用程序使用此共享库,并且基本上可以写成为:
Interface* foo = Implementation::giveMeImplPtr();
foo->Foo(0xff);
换句话说,该应用程序不具有从Interface
派生的任何类,它仅仅使用它。
现在,说我想重载Foo(uint16_t arg)
与Foo(uint32_t arg)
,我是做安全:
class Interface {
public:
static Interface* giveMeImplPtr();
...
virtual void Foo(uint16_t arg) = 0;
virtual void Foo(uint32_t arg) = 0;
...
}
,并重新编译我的共享库,而无需重新编译应用程序?
如果是这样,有什么不寻常的注意事项我需要注意?如果没有,除了使用命中和升级版本库之外,还有其他选择,从而打破向后兼容性吗?