[Qt-interest] QSharedDataPointer and forward declared classes
Lukas Geyer
lgeyer at gmx.at
Tue Mar 2 12:58:28 CET 2010
>>> 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.
>> 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.
Best,
Lukas.
More information about the Qt-interest-old
mailing list