string to character conversion

This is a discussion on string to character conversion within the C++ Programming forums, part of the General Programming Boards category; >it will still work if i don't pass it by reference ( if i pass cout, not an ostringstream object ...

  1. #16
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >it will still work if i don't pass it by reference ( if i pass cout, not an ostringstream object )
    If you use operator<< then you're passing the stream object by reference whether it seems that way or not.
    My best code is written with the delete key.

  2. #17
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >why the standard doesn't allow me to remove that referece?
    I don't know, why don't you ask them? Go to comp.std.c++ and ask that same question. I'm sure some of the committee members floating around there will tell you why.
    My best code is written with the delete key.

  3. #18
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >But ypu are ABSOLUTELY sure that the standard says so?
    I can't quote line and verse from memory if that's what you mean, though I'm quite sure. But I'm not about to go rooting through the standard for that tiny tidbit of information to verify it. If you want to get the standard and prove me wrong then by all means, do so.
    My best code is written with the delete key.

  4. #19
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,088
    Why on earth would you want to take in a copy of the stream? If you remove the reference **&**, then a copy is made. What's the point of adding data to a stream when it is just a copy? The stream in the code that calls the operator << won't get modified, only the copy will. So basically your operator<< will do nothing without the stream parameter being a reference.
    Quote Originally Posted by C+++C_forever
    why does the standard care. it will still work if i don't pass it by reference
    No it won't work, only the copy will get modified, and the original stream will be unchanged.
    Quote Originally Posted by C+++C_forever
    it seems that the standard is more clever than what i used to believe!
    I wouldn't underestimate the abilities of the people who work on those kinds of things. It might be a better idea to always assume you are the one who is wrong if you disagree. Then you'll be right 99.9% of the time.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  2. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 11:03 AM
  3. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 10:33 PM
  4. Another overloading "<<" problem
    By alphaoide in forum C++ Programming
    Replies: 18
    Last Post: 09-30-2003, 11:32 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21