Jump to content
  • Advertisement
Sign in to follow this  
3dcgmodeling

ostream_iterator

This topic is 4255 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

copy(A.begin(), A.end(), ostream_iterator<const char*>(cout, "\n")); ostream_iterator is class and ostream_iterator<const char*>(cout, "\n") create a temp object and call a constructor with parameter cout and "\n".do I guess right? I know copy use instance of ostream_iterator to traverse A.begin() to A.end(). but How does ostream_iterator know A? it seem no parameter(information) passed to ostream_iterator.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by 3dcgmodeling
ostream_iterator is class and ostream_iterator<const char*>(cout, "\n") create a temp object and call a constructor with parameter cout and "\n".do I guess right?
Yes.
Quote:
I know copy use instance of ostream_iterator to traverse A.begin() to A.end(). but How does ostream_iterator know A? it seem no parameter(information) passed to ostream_iterator.
The ostream_iterator isn't traversing A, the copy function is (or more precisely, it is telling an iterator to). The copy function is calling member functions on the ostream_iterator to pass the elements it copies from A. The ostream_iterator only needs to know the type of the elements, which is provided in the template parameter <const char*>.

To make it easier, think of the flow of information in terms of "push" and "pull". You can push information to an object in function arguments. You can pull information out of an object from return values from functions. The copy function pulls information out of A (through the iterators), and pushes it to the ostream_iterator.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!