the difference between this two?
struct Information {
ifstream* in;
ofstream* out;
...
};
.....
((*info).in)->eof() //this one
(*(*info).in).eof() // and this one
so, info is a Information struct, is there any different between the two shown above? my guess is they are the same. and what is "->" and "." called?
wildplace
Junior Poster in Training
72 posts since Dec 2009
Reputation Points: 10
Solved Threads: 4
Skill Endorsements: 0
so, info is a Information struct
Those two lines are only meaningful if info is a pointer to an Information object.
is there any different between the two shown above?
Nope, the arrow operator is for convenience when dereferencing a pointer member.
and what is "->" and "." called?
They're the the arrow and dot operators. :)
deceptikon
Challenge Accepted
3,499 posts since Jan 2012
Reputation Points: 822
Solved Threads: 481
Skill Endorsements: 58
You use the -> (pointer-to) operator to dereference a member of a pointer to an object/struct. You use the . (dot) operator to dereference a member of an object (not a pointer to the object), or a reference to an object. In your example, the operator * is what makes the change, in that it means something like "this is a reference to an object, not a pointer to the object). So, using the member "this" which is a pointer to the currently scoped object, you would use the pointer-to operator (->) such as "this->in", but if you use "*this" (which means a reference to the thing "this" points to), you would do "(*this).in". Confused yet? :-) This distinction between pointers and references is one of the things that causes the most difficulty for emerging C++ programmers.
rubberman
Posting Maven
2,682 posts since Mar 2010
Reputation Points: 378
Solved Threads: 316
Skill Endorsements: 53