I have been playing around with C++ for awhile now and was wondering: what's the differnce between the [instance].[function] and [instance]->[function]? Does the dot notation just run the value and the arrow notation store value inside the instance?
pars99 0 Junior Poster in Training
Recommended Answers
Jump to PostThey both do the same thing -- its just how the object is declared. The -> is pointer notation. Some examples:
class MyClass { public: int x; }; // in this function pMyClass is a pointer, so it requires -> to // reference any of it's objects …
Jump to PostA slightly simpler explanation is that the arrow operator is syntactic sugar for accessing a member of a pointer to structure or class:
p->member
is equivalent to(*p).member
. Since the latter is awkward to type and it's very common to have a pointer to a structure or class, the arrow …
All 5 Replies
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
rubberman 1,355 Nearly a Posting Virtuoso Featured Poster
pars99 0 Junior Poster in Training
rubberman 1,355 Nearly a Posting Virtuoso Featured Poster
pars99 commented: Yes, sorry about that. Thank you. :-) +1
deceptikon 1,790 Code Sniper Team Colleague Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.