c++ - What does ClassName& as a return type mean? -
i try understand following code (taken here):
template <class t> class auto_ptr { t* ptr; public: explicit auto_ptr(t* p = 0) : ptr(p) {} ~auto_ptr() {delete ptr;} t& operator*() {return *ptr;} // <----- problematic row. t* operator->() {return ptr;} // ... }; i cannot understand mean when use t& return type of function. if t pointer integer (or other type), interpret t& integer (or other corresponding type). in above given code t not pointer. t class, , 1 of members (ptr) pointer objects of class t not class of pointers. so, t& return type mean?
it means same outside context of function's return type, i.e. t& reference t. in case, function returns reference object of type t caller can use observe (and alter, if t not const-qualified) referenced object.
Comments
Post a Comment