Search code examples
c++qttemplatessmart-pointersqsharedpointer

Please explain this expression


class TestPtr : protected QSharedPointer<Test>

where Test is an abstract interface class. The TestPtr class should serve as the smart pointer class.

Does this mean class TestPtr is derived from the class Test ? Is class test enclosed in a smart pointer? I read that QSharedPointer is a template class. Could somebody please clarify?


Solution

  • What it doesn't mean

    1. That TestPtr derives from Test -- it does not.
    2. That class Test is enclosed in a smart pointer (but close: it means that instances of TestPtr will actually be smart pointers to Test without letting the world know about it except as the author of TestPtr explicitly chooses to)

    What it means

    It means that TestPtr wants to implement the functionality of a smart pointer to Test (which is what QSharedPointer<Test> is -- please note I have no idea exactly what QSharedPointer does, I 'm just "reading what's in the name").

    To achieve this, the author of TestPtr plans to extensively use the functionality built into the inner works of QSharedPointer (that's why TestPtr inherits instead of having a QSharedPointer member -- to be able to use the protected members of QSharedPointer).

    However, the author plans for TestPtr to not be equivalent to a QSharedPointer<TestPtr> even if the class has about the same functionality (we don't know the reason for this with the given information). That's why the inheritance is not public.