Function resolution for temp object

M

Mark Gilbert

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::eek:stringstream os;
// This calls ::eek:perator<<(ostream &, const char *)
os << "str";

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

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

Thanks very much,
Mark Gilbert
 
M

mlimber

Mark said:
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::eek:stringstream os;
// This calls ::eek:perator<<(ostream &, const char *)
os << "str";

// But, this calls ostringstream::eek:perator<<(const void *)
std::eek:stringstream() << "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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top