Dereference operator * that returns a reference to the item pointed by the object.
Operator -> that returns the pointer to the object. It allows to use the my_unique_ptr object for class member access.
would i write operatir -> as
Type* operator->(); or Type* operator-> () const; why?
how do i write derefernce?
Why would it be a pointer? Your operator implies that you are going into the pointer to get the thing itself, so wouldn't it just return type, not type*?
The operator-> can be marked const if you're doing a re-implementation of a smart-pointer-esque object, because the function doesn't need to modify the pointer itself.
jonnin, I think that's just how it works with operator overloading. Kinda like how post-increment ++ has special rules, the -> operator also has special rule in that it automatically dereferences the returned object to access its member.
The overload of operator -> must either return a raw pointer, or return an object (by reference or by value) for which operator -> is in turn overloaded.
Right, the -> and * operators can be marked as const, as they don't need to change the unique_ptr object itself. Your operator= signature also looks OK as far as I can tell, but I don't know the details of any pitfalls or "gotchas" of implementing a smart ptr, so my advice would just be to try it out and experiment.
also
my_unique_ptr<Type>& operator=(my_unique_ptr<Type> &&target) is this how u write it
or is it
my_unique_ptr<Type>& operator=(my_unique_ptr && target)
or
my_unique_ptr & operator=(my_unique_ptr && target)
also for pointers is it like typename * ptr or does it have to be typename* ptr? or like operator * or operator* does spacing matter?