1,105,594 Community Members

the difference between this two?

Member Avatar
wildplace
Junior Poster in Training
72 posts since Dec 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 4 [?]
Skill Endorsements: 0 [?]
 
0
 
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?

Member Avatar
deceptikon
Eternally Awesome
4,690 posts since Jan 2012
Reputation Points: 1,341 [?]
Q&As Helped to Solve: 688 [?]
Skill Endorsements: 104 [?]
Administrator
Featured
 
1
 

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. :)

Member Avatar
rubberman
Senior Poster
3,999 posts since Mar 2010
Reputation Points: 513 [?]
Q&As Helped to Solve: 501 [?]
Skill Endorsements: 87 [?]
 
0
 

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.

Member Avatar
ejosiah
Junior Poster
196 posts since Feb 2008
Reputation Points: 4 [?]
Q&As Helped to Solve: 23 [?]
Skill Endorsements: 3 [?]
 
0
 

You need to do some reading. This link will be helpfull C++ an hour a day
You should find the answer to alot of your questions there

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article