473,322 Members | 1,522 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Function resolution for temp object

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
1 985
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
2
by: Andrew | last post by:
I have written two classes : a String Class based on the book " C++ in 21 days " and a GenericIpClass listed below : file GenericStringClass.h // Generic String class
5
by: Tommy Lang | last post by:
Hi! I am trying to write a function that goes through an array of objects(class Student) and checks if object name(student name)matches search string(char *). I want the function to return a...
14
by: lutorm | last post by:
Hi, I'm having a problem with a return statement being parsed to return a function (I think). Check here: template <typename T> class A {}; template <typename T> class maker_of_A { public:...
14
by: jagadeeshbp | last post by:
Hi, I am having a CPP file which defines a class: class xyz{ public: int (*funcptr)(void); } A function foo is defined in a "C file"
33
by: Pushkar Pradhan | last post by:
I'm using clock() to time parts of my code e.g. clk1 = clock(); /* code */ clk2 = clock(); /* calculate time in secs */ ...... clk1 = clock(); /* code */ clk2 = clock();
5
by: Andrew Poulos | last post by:
I tested the JSON parse/to code from json.org and it works but I don't understand how. Could someone explain how something in this format works: (function() {...})(); Andrew Poulos
14
by: emailscotta | last post by:
Some of the object properties in the Dojo Toolkit are set to objects but they are using syntax like this: object.property = new function() { this.property = someValue; this.property =...
2
by: f rom | last post by:
----- Forwarded Message ---- From: Josiah Carlson <jcarlson@uci.edu> To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org Sent: Monday, December 4, 2006 10:03:28 PM Subject: Re: ...
13
by: JD | last post by:
Hi, My associate has written a copy constructor for a class. Now I need to add an operator = to the class. Is there a way to do it without change her code (copy constructor) at all? Your help...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.