The following is an attempt at implementing a shared pointer with a modified semantics of operator==
:
template <typename T>
struct deref_shared_ptr: private std::shared_ptr<T> {
using Base = std::shared_ptr<T>;
// ... using statements to include functionality from the base.
bool operator==(const deref_shared_ptr rhs) const {
return (**this == *rhs);
}
};
I am struggling with implementing an equivalent of std::make_shared
for this type. This is my attempt:
template< class T, class... Args >
deref_shared_ptr<T> make_deref_shared( Args&&... args ) {
return reinterpret_cast<deref_shared_ptr<T>>(std::make_shared<T>(args...));
}
This does not work: the compiler (g++ 5.4.0
) complains about an invalid cast. Why does it not work and what should I do instead of this cast?
friend
. It's not a sin. – Plantagenetstd::shared_ptr
argument? – Scibert