I'm using some smart pointer implementation that contain the following operators :
template<class T>
class my_unique_ptr {
public:
...
operator T() {
return _t;
}
T *operator &() {
return &_t;
}
private:
T _t;
};
I'm looking to get the original value from type T that wrapped by the pointer class.
The &
operator works fine but it gives my pointer and not the value itself.
Therefore, I wish to call the T()
operator (just like get()
in std::unique_ptr
)
I tried to use the variable directly, but it refers to it as my_unique_ptr<T>
instead of T
.
void func(myClass c);
int main()
{
my_unique_ptr<myClass> x = new myClass(..);
func(x);
}
but I get error of unable cast from type 'my_unique_ptr' to pointer type 'myClass'
How can I call this operator ?