QExplicitlySharedPointer and inheritance

What is the best way to use QExplicitlySharedPointerand inherited classes. I would like when BaseClass exits it to have its d-pointer QExplicitlySharedPointer<BaseClassPrivate>, and when I have the Derived class on top of this base class, I would like d to be QExplicitlySharedPointer<DerivedClassPrivate>.

I tried to inherit DerivedClassPrivate from BaseClassPrivate, and then make the d pointer protected and override the d pointer in my derived class, but now it seems like I have two copies of the d pointer that are local to the class they are defined in ... that not what i want.

0
source share
1 answer

How about this:

template< typename P = BaseClassPrivate >
class BaseClass
{
public:
  void myBaseFunc() { d->myBaseFunc(); }
protected:
  QExplicitlySharedDataPointer< P > d;
};

class DerivedClass : public BaseClass< DerivedClassPrivate >
{
public:
  void myDerivedFunc() { d->myDerivedFunc(); }
};
+2
source

All Articles