Hide specific methods of a typed class in a smart pointer

49 Views Asked by At

I use the following code

template <typename T> std::shared_ptr<T> comToShared(T* comObject) {
    comObject->AddRef();
    return std::shared_ptr<T>(comObject, [=](auto) {
        comObject->Release();
    });
}

to convert a COM object into a shared_ptr, as that fits better with the rest of my codebase. The problem is that I still can (and occasionally do) call AddRef() or Release() on the interior pointer and cause an over-release/over-retain issue.

Is there a way to hide just those two methods in this case so that using them causes a compile error whilst leaving the rest of the interface accessible?

0

There are 0 best solutions below