'std::atomic<T*> refCount in own implementation of shared ptr

According to the assignment, it is necessary to make refCount not size_t, but std::atomic. Initially it was like this:

namespace smartptr {
template <typename T> class sharedPtr {

    private:
      T *ptr = nullptr;
      size_t *refCount = nullptr;
    
    public:
      sharedPtr() = default;
    
      explicit sharedPtr(T *ptr_) : ptr(ptr_), refCount(new size_t(1)) {}
    
      sharedPtr(const sharedPtr &obj) : ptr(obj.ptr), refCount(obj.refCount) {
        if (nullptr != obj.refCount)
          *refCount = *refCount + 1;
      }
    
      sharedPtr(sharedPtr &&obj) noexcept : ptr(obj.ptr), refCount(obj.refCount) {
        obj.ptr = nullptr;
        obj.refCount = nullptr;
      }
.....

How to correctly apply the operations of adding, deleting, creating refCount, taking into account the fact that the type is atomic? For example, in the first constructor I tried to do this:

explicit sharedPtr(T *ptr_) : ptr(ptr_), refCount.store(1) {}

But an error comes up:

no matching member function for call to 'store'

c++


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source