c++ - Is (*i).member less efficient than i->member -
having
struct person { string name; }; person* p = ... assume no operators overloaded.
which more efficient (if any) ?
(*p).name vs. p->name
somewhere in of head hear bells ringing, * dereference operator may create temporary copy of object; true?
the background of question cases this:
person& person::somefunction(){ ... return *this; } and began wonder, if changing result person* , last line return this make difference (in performance)?
when return reference, that's same passing pointer, pointer semantics excluded.
pass sizeof(void*) element, not sizeof(yourclass).
so when that:
person& person::somefunction(){ ... return *this; } you return reference, , reference has same intrinsic size pointer, there's no runtime difference.
same goes use of (*i).name, in case create l-value, has same semantics reference (see here)
Comments
Post a Comment