Boost logo

Boost Users :

Subject: [Boost-users] [BLL] Problem with print vector elements.
From: mik (mirko.cambi_at_[hidden])
Date: 2012-04-12 05:06:08


Hi,

I'm trying to use thew BLL for the first time and I've the following
program:

class Date
{
public:
   Date(long d): _lDate(d) {}
   long getDate() const { return _lDate; }
   [...]
private:
   long _lDate;
};

std::ostream& operator<<(std::ostream &s, const Date &x)
{
   [...]
}

struct C
{
   C(long d): date(d) {}
   Date date;
};

int main()
{
   const C c(46000);
   std::cout << boost::bind(&C::date, boost::lambda::_1)(c) << std::endl;

   std::vector<C> cont(1, C(46000));
   std::for_each(cont.begin(), cont.end(), std::cout <<
boost::bind(&C::date, boost::lambda::_1));

   return 0;
}

The first std::cout is ok. But for the second one nested int the for_each I
get this message error:

error C2679: binary '<<' : no operator found which takes a right-hand
operand of type 'boost::_bi::bind_t<R,F,L>' (or there is no acceptable
conversion)
with
[
   R=const Date &,
   F=boost::_mfi::dm<Date,C>,
   L=boost::_bi::list1<boost::arg<1>>
]
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\INCLUDE\ostream(653):
could be 'std::basic_ostream<_Elem,_Traits> &std::operator
<<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const
char *)' [found using argument-dependent lookup]
with
[
   _Elem=char,
   _Traits=std::char_traits<char>
]

Can you help me?

Thank you,
    Mirko

**



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