Embedding implicitly shared classes outside of Qt

I am familiar with how Qt uses D pointers to manipulate data. How to do this in my code?

I tried this method:

1) move all the data to the structure 2) add QAtomicInt to the structure 3) implement the a = operator and change its constructor / deconstructor to check the number of links.

The problem is that when I go to make a shallow copy of the object, I get the error message QObject = private. How am I going to do this?

Here is an example of my copy statement:

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 it wrong?

+4
source share
1 answer

AFAIK QObjects are not intended for copying. So QObject has a private operator = so the question is why you want to declare it, and if you do, should your object really be a QObject?

0
source

Source: https://habr.com/ru/post/1306741/


All Articles