Boost logo

Boost Users :

From: Vladimir Prus (ghost_at_[hidden])
Date: 2005-03-02 04:05:13


Patrick M?zard wrote:

> namespace testns
> {
>
> struct Test
> {
....
> };
>
> namespace
> {
>
> std::ostream& operator<<(std::ostream& o, Test const& t)
> {
> return o<<t.s;
> }

...
> Does not compile and gives me a:
> C2679: binary 'operator' : no operator defined which takes a right-hand
> operand of type 'const testns::Test' (or there is no acceptable
> conversion), the failure being issued by "void
> boost::test_tools::tt_detail::print_log_value<T>::operator
> ()(std::ostream &,const T &)"
>
> However, if I define operator<< as a public member of testns::Test it
> compiles. Same thing if I move it outside the anonymous namespace, with or
> without static linkage.

I think defining operator<< in the same namespace as the class 'Test' is the
only way. Otherwise, it won't be found by ADL and ADL is the only way to
boost.test to find your operator<<.

> Note these workaround do not work or cannot be applied if the type is
> declared by a typedef. In this case, I have to define again the
> operator in namespace
> boost.test_tools.tt_detail.

If the type is declared by a typedef:
 
    typedef foo::C C2;

you can define the operator<< in the 'foo' namespace, and that should work.

- Volodya


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