Query related to assigning an address to a shared_ptr

I have read that if we want to assign a shared_ptr to an already existing address of an object, then we need to define an empty custom deleter so that it is not tried to be deleted from heap. My question is if we have a shared_ptr object allocated using new and another shared_ptr object using an address, will there be any issue freeing the heap memory and maintaining reference counts etc?

some_class a;
shared_ptr<some_class> b(&a, custom_deleter);

shared_ptr<some_class> c(new some_class());

Answers


Those shared_ptrs are completely independent. They both manage different objects and will use the appropriate deleter for those objects, so there are no issues with doing that.


Need Your Help

Comparing class instances and attaining cumulative "score"

python class comparison subclassing

So, I have two instances of a class Person and I am trying to do some comparisons. sunis one of several attributes of each instance is defined by two randomly generated numbers. I have the following