I have a class that inherits two interfaces:
class Multi : public IFoo, public IBar { public: virtual ~Multi();
Unfortunately, this class cannot be decomposed into two separate classes for each interface. In fact, in the class implementation these objects (Foo and Bar) are closely related, but in the future they may become separate.
Another class wants to use the Multi-class, pointing to IFoo and IBar:
class ClientClass { public: ClientClass();
In the constructor, I am doing something like:
ClientClass::ClientClass(){ auto pMulti = new Multi; foo_ = std::shared_ptr<IFoo>(pMulti); bar_= std::shared_ptr<IBar>(pMulti); }
But each of these common pointers has a separate reference counter, and this leads to the removal of the already deleted class destruction pointer, am I correct?
- How do I treat him?
- What is best suited for this?
source share