By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,433 Members | 1,649 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,433 IT Pros & Developers. It's quick & easy.

Function resolution for temp object

P: n/a
Can you explain this to me? If I make a variable of type ostringstream and
do << "str", I get what I want, but if I create a temporary object of the
same type, I get a different version of operator<<.

std::ostringstream os;
// This calls ::operator<<(ostream &, const char *)
os << "str";

// But, this calls ostringstream::operator<<(const void *)
std::ostringstream() << "str";

I am using MSVC 2005, though I think the behavior was the same with MSVC
2003.

Thanks very much,
Mark Gilbert
Nov 22 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Mark Gilbert wrote:
Can you explain this to me? If I make a variable of type ostringstream and
do << "str", I get what I want, but if I create a temporary object of the
same type, I get a different version of operator<<.

std::ostringstream os;
// This calls ::operator<<(ostream &, const char *)
os << "str";

// But, this calls ostringstream::operator<<(const void *)
std::ostringstream() << "str";

I am using MSVC 2005, though I think the behavior was the same with MSVC
2003.

Thanks very much,
Mark Gilbert


Methinks it's because you cannot bind a temporary to a non-const
reference (as in the first parameter to operator<<(ostream &, const
char *) ).

Cheers! --M

Nov 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.