I am reading the implementation of auto_ptr in C++ STL.
I see that commonly needed operations on pointers like -> and * are overloaded so that they retain the same meaning. However, will pointer arithmetic work on auto pointers?
Say I have an array of auto pointers and I want to be able to do something like array + 1 and expect to get the address of the 2nd element of the array. How do I get it?
I don’t have any practical application for this requirement, just asking out of curiosity.
An auto_ptr can only point to a single element, because it uses
delete(and notdelete[]) to delete its pointer.So there is no use for pointer arithmetic here.
If you need an array of objects, the usual advice is to use a std::vector instead.