Re: pimpl and Qt
18 May
2005
18 May
'05
7:59 p.m.
private: struct Private; boost::scoped_ptr<Private> d; };
When working with Qt, i suggest to write the Pimpl idiom like this, since the generated code from moc needs access to your FooPrivate, in cases. struct FooPrivate; class Foo { private: FooPrivate* pimpl_; }; --David
19 May
19 May
10:15 a.m.
New subject: pimpl and Qt
> When working with Qt, i suggest to write the Pimpl idiom like this, > since the generated code from moc needs access to your FooPrivate, > in cases. > > struct FooPrivate; > class Foo > { > private: > FooPrivate* pimpl_; > }; I would not suggest using such implementation. It has few problems: 1. Global namespace pollution. That can be easily fixed, by making FooPrivate innter class of Foo. 2. High danger of unexpected behaviour if implementation of assignment and copy contrsuctor is omitted or incorrect. If you forget to implement copy operator and then copy such object - results will be devastating - both objects will share pointer on same state. For same reason, I suggest using scoped_ptr over shared_ptr. If you'll try to copy object with no assignment operator and scoped_ptr-based pimpl - you will get a nice compile error. Using shared_ptr it will work fine, but, probably, it is not what was intended to do (until, of course, the intention is implicitly shared state). -- Best regards, Zigmar
7132
Age (days ago)
7133
Last active (days ago)
1 comments
2 participants
participants (2)
-
gruenedd@idmt.fraunhofer.de
-
Pavel Antokolsky aka Zigmar