[Qt-interest] QSharedDataPointer and forward declared classes

Thiago Macieira thiago at kde.org
Tue Mar 2 14:31:12 CET 2010


Em Terça-feira 02 Março 2010, às 12:58:28, Lukas Geyer escreveu:
> >>> The compiler error was caused by an missing ctor/dtor for TestClass
> >>> (d'oh!).
> >> 
> >> Actually, there are two more missing.
> >> 
> >> class TestClass
> >> {
> >> 
> >> public:
> >>      TestClass();
> >>      TestClass(const TestClass&other);
> >>      ~TestClass();
> >>      TestClass&operator=(const TestClass&other);
> >> 
> >> private:
> >>      QExplicitlySharedDataPointer<TestClassData>  data;
> >> 
> >> };
> 
> Leaving good habits out, do we actually need a user-defined copy ctor /
> assignment operator in this example? The compiler will do a member-wise
> copy which will be fine here, assuming QExplicitlySharedDataPointer
> implements both and our copy ctor does nothing more than
> data(other.data) as we want reference counting instead of a deep copy.

Hi Lukas,

You're missing the point that was the reason for the thread. The TestClassData 
class is forward-declared only:

> >> If they are inline, the compiler will instantiate the access to
> >> TestClassData in the caller's code, which means TestClassData needs to
> >> be fully defined and that's not what you want. Note that implicit
> >> implies inline.
> 
> I haven't paid attention to the fact that QExplicitlySharedDataPointer's
> ctors and dtor are inline and it is clear that we run into this problem.
> Sometimes you are missing the forest through the trees.

Of course they are inline. It's a template class. Non-inline template classes 
are a very minor exception, not the rule.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Senior Product Manager - Nokia, Qt Development Frameworks
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100302/f4bbd20d/attachment.bin 


More information about the Qt-interest-old mailing list