jeudi 1 octobre 2020

mapping unique_ptr to shared_ptr design

I have an unique_ptr in my main application (which provides some service to other applications). Now I want to share this instance of unique_ptr to multiple applications which require service from my main application.

The main application will be the owner of that unique_ptr object.

for example, my unique_ptr object might have a set of Qt signals and other applications will listen to these signals for service.

enter image description here

Right now I'm getting raw pointer from unique_ptr and returning it to other applications, but what happens if some application deletes that raw pointer?

should I change my unique_ptr to shared_ptr and give weak_ptr to other applications?

Aucun commentaire:

Enregistrer un commentaire