Implementing implicitly shared classes outside of Qt
Posted
by Timothy Baldridge
on Stack Overflow
See other posts from Stack Overflow
or by Timothy Baldridge
Published on 2010-04-12T20:39:25Z
Indexed on
2010/04/12
20:43 UTC
Read the original article
Hit count: 242
I'm familiar with the way Qt uses D-pointers for managing data. How do I do this in my code?
I tried this method:
1) move all data into a struct 2) add a QAtomicInt to the struct 3) implement a = operator and change my constructor/deconstructor to check-up on the reference count.
The issue is, when I go to do a shallow copy of the object, I get an error about QObject declaring = as private. How then do I accomplish this?
Here's an example of my copy operator:
HttpRequest & HttpRequest::operator=(const HttpRequest &other)
{
other.d->ref.ref();
if (!d->ref.deref())
delete d;
d = other.d;
return *this;
}
Am I going about this the wrong way?
© Stack Overflow or respective owner