[Qt-interest] QSharedDataPointer and forward declared classes
Raul Metsma
raul at innovaatik.ee
Tue Mar 2 10:53:24 CET 2010
I think its good to update documentation also with same story
http://doc.trolltech.com/4.6/qshareddatapointer.html
There is only small hint
"Note that class Employee also has a trivial copy constructor defined,
which is not strictly required in this case."
Raul Metsma
On 03/02/2010 11:05 AM, Thiago Macieira wrote:
> Em Terça-feira 02 Março 2010, às 09:04:00, Lukas Geyer escreveu:
>> The compiler error was caused by an missing ctor/dtor for TestClass
>> (d'oh!).
>>
>>> #include<QtCore/QExplicitlySharedDataPointer>
>>> class TestClassData;
>>> class TestClass
>>> {
>>>
>>> private:
>>> QExplicitlySharedDataPointer<TestClassData> data;
>>>
>>> };
>>
>> TestClass() and ~TestClass() missing here.
>
> Actually, there are two more missing.
>
> Any C++ developer should know the answer to this: what are the four implicit
> methods in a class? (i.e. methods that the compiler will create for you if you
> don't say otherwise)
>
> So you actually need to define all four in your class and they must not be
> inline:
>
> class TestClass
> {
> public:
> TestClass();
> TestClass(const TestClass&other);
> ~TestClass();
> TestClass&operator=(const TestClass&other);
>
> private:
> QExplicitlySharedDataPointer<TestClassData> data;
> };
>
> 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.
>
> If you don't want your object to be copyable, then move the copy constructor
> and assignment operators to the private: part. You don't have to implement
> them, because no one will be calling them. That's what the Q_DISABLE_COPY
> macro does, until C++0x comes with deleted functions.
>
> Bonus: you may want to add operator== and operator!= too.
>
>
>
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
More information about the Qt-interest-old
mailing list