我试图重构一些代码,同时保留现有的功能.我无法将指向对象的指针转换为基接口,然后在以后获取派生类.在某些情况下,程序使用工厂对象来创建这些对象的实例.
以下是我正在使用的类的一些示例.
// This is the one I'm working with now that is causing all the trouble.
// Some, but not all methods in NewAbstract and OldAbstract overlap, so I
// used virtual inheritance.
class MyObject : virtual public NewAbstract, virtual public OldAbstract { ... }
// This is what it looked like before
class MyObject : public OldAbstract { ... }
// This is an example of most other classes that use the base interface
class NormalObject : public …Run Code Online (Sandbox Code Playgroud)