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?

Recommended Answers

All 3 Replies

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

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.

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

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.