"Rolf Magnus" <> wrote in message
news:e3uq9a$c50$02$...
> Jim Langston wrote:
>
>> I'm a little confused. I have a class function declared like:
>>
>> const CItem& operator << (const std::string &sIn);
>>
>> Which I use like this:
>>
>> CItem Item;
>> Item << "blaster01,1,0,...,0,0,20,0,0,20,eol";
>>
>> At the end of the method it does:
>> return *this;
>>
>> My question is, is my const on the return value doing anything?
>
> Well, you won't be able to chain the operator calls, like:
>
> Item << "Hello, " << "world";
>
> Basically, returning the reference at all doesn't make much sense if it's
> const.
>
>> I don't know why I even have it there (maybe I copied this method from
>> some source).
>>
>> const CItem& seems to be to define a reference to a CItem that is
>> constant.
>> Is that correct?
>
> Yes.
Okay, so this begs the question, should I even be overriding the operator <<
anyway? If I'm not returning anything, maybe it would be better to just
make a function like
void LoadFromString( const std::string& sIn )
|