Re: ostream, istream, and String^
- From: "Holger Grund" <holger.grund@xxxxxxxxxxxxxxx>
- Date: Fri, 16 Dec 2005 03:18:59 +0100
"Peteroid" <peter_oliphant@xxxxxxx> wrote
>> Would you care to explain which error you see?
>
> The ones I indicated, both of which are something like 'no overload of
> '<<' or '>>' exists for String^".
>
That doesn't make sense. The operators you have provided are both matches.
Please do post the full error message (am I really the only one who reads
and understands compiler diagnostics *sigh*)
>>> I don't know what you're trying to achive, but the
>>> implementation looks quite pointless.
>
> Let me expalin it to you with code that does work. This code does work:
>
>>> ostream% operator <<( ostream% output, int value)
>>> {
>>> output << value ; //ok
>>> return output ;
>>> }
>
I don't even see how this would compile. Given you have included
iostream there's
std::basic_ostream<..>& std::basic_ostream<..>::operator <<( int )
The above "output << value" should therefore be ambigious. If
ostream is incomplete, the above call would be recursive. Anyway,
your implementation does not add any real value.
> This takes the output stream given as a parameter, uses ITS '<<' operator
> for 'int' and adds 'value' to the stream, and then returns the resulting
> stream. This is the standard way of doing streaming, such as when saving
> values serially to a file.
>
That's not quite correct.
output << value
looks for both member and non-member operators. Non-members in associated
namespaces (std for the above example) are considered. Therefore the
expression
is ambigious.
Can you give a full compilable example?
>>>the implementations recursively call themselves.
>
> The '<<' used in the implementation of the method is not the same '<<'
> this method defines.
>
I fail to see how overload resolution could find a better match.
> So my problem is because String^ does not have a natural overload of '<<'
> which is used to add it to streams. THAT is what I need, is a way to
> send/recieve String^'s through a stream (both directions). I'm guessing
> part of the problem is that String^ are both variable in length and
> mutable...
>
I've showed you to overloads that should work (I'm not quite sure about the
encoding and conversion, .NET Strings are Unicode while ostream is a
8-bit encoding)
BTW: .NET Strings are immutable. Therefore you should really use a reference
to a handle (String^%)
-hg
.
- Follow-Ups:
- Re: ostream, istream, and String^
- From: Peteroid
- Re: ostream, istream, and String^
- References:
- ostream, istream, and String^
- From: Peteroid
- Re: ostream, istream, and String^
- From: Peteroid
- Re: ostream, istream, and String^
- From: Holger Grund
- Re: ostream, istream, and String^
- From: Peteroid
- ostream, istream, and String^
- Prev by Date: Drawing to memory DC from CDoc
- Next by Date: Re: ostream, istream, and String^
- Previous by thread: Re: ostream, istream, and String^
- Next by thread: Re: ostream, istream, and String^
- Index(es):
Relevant Pages
|