|
Boost : |
From: Jeff Garland (jeff_at_[hidden])
Date: 2005-11-28 07:25:50
On Sun, 27 Nov 2005 09:56:33 +0200, Roman Yakovenko wrote
> Good morning.
>
> Consider next use case:
>
> struct my_ldt : public boost::local_time::local_date_time_base<>{
> my_ldt()
> : boost::local_time::local_date_time_base<>(
> boost::posix_time::ptime() , boost::shared_ptr<
> boost::date_time::time_zone_base<boost::posix_time::ptime> >() ) {}
>
> };
>
> int _tmain(int argc, _TCHAR* argv[])
> {
> boost::posix_time::ptime t;
> my_ldt m;
> m == t;
> //^^^^^^^^
> //this will not compile ( at least on VC 7.1 )
> //the error is error C2678: binary '==' : no operator found which
> takes a left-hand operand of type 'my_ldt' (or there is no
> acceptable conversion) }
>
> fix:
>
> Add next code to the local_date_time_base class
>
> typedef date_time::base_time<utc_time_,
> boost::posix_time::posix_time_system> base_type;
>
> using base_type::operator==;
> using base_type::operator<;
> using base_type::operator-;
Actually it's intentional to not do an automatic conversion there. Call
utc_time() to get the ptime. So:
boost::posix_time::ptime t;
my_ldt m;
m.utc_time() == t;
Jeff
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk