Boost logo

Boost Users :

From: klaus triendl (triendl.kj_at_[hidden])
Date: 2006-07-04 03:23:17


Peter Dimov wrote:
> klaus triendl wrote:
>
> [...]
>
>> MyStream& operator <<(MyStream& os, const int&)
>> {
>> return os;
>> }
>>
>> int main()
>> {
>> list<shared_ptr<int> > cont;
>> MyStream osTop;
>> MySubStream osSub(&osTop);
>
> MyStream& tmp = osSub;
>
>> for_each(cont.begin(), cont.end(), ref(osSub) << *_1);
>
> for_each( cont.begin(), cont.end(), tmp << *_1 );
>
> // or, if the above doesn't work - it should -
>
> for_each( cont.begin(), cont.end(), ref(tmp) << *_1 );
>
>> return 0;
>> }
>> ----
>>
>> g++ outputs error:
>> '/usr/include/boost/lambda/detail/operator_lambda_func_base.hpp:212:
>> error: conversion from 'MyStream' to non-scalar type 'MySubStream'
>> requested'.
>
> Lambda sees that you are invoking operator<< on a MySubStream& and deduces
> the return type to be MySubStream&; it isn't smart enough to see that you're
> actually using the operator<< definition for the base class MyStream.

I thought that it would be converted implicitly in the end by the compiler..
Can I make it smart enough?

--
Klaus

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net