BOOST_CHECK fails to compile operator<< for custom types

前端 未结 4 1397
温柔的废话
温柔的废话 2020-12-30 11:43

I wrote this really trivial class so that it\'s clear what my problem is:

class A
{
public:
    int x;
    A(int y) {x=y;}
    bool operator==(const A &o         


        
4条回答
  •  情深已故
    2020-12-30 12:16

    This is a supplement to the excellent answer from John Dibling. The problem seems to be that there needs to be an output operator in the right namespace. So if you have a global output operator<< defined, then you may avoid this error (at least with Visual Studio 2015, aka vc14, and boost 1.60) by defining another one in the boost::test_tools::tt_detail namespace that forwards to the global operator. This minor tweak enables one to avoid a strange and more verbose specialization of the print_log_value class. Here is what I did:

    namespace boost {
    namespace test_tools {
    namespace tt_detail {
    std::ostream& operator<<(std::ostream& os, Mdi::Timestamp const& ts)
    {
        return ::operator<<(os, ts);
    }
    }  // namespace tt_detail
    }  // namespace test_tools
    }  // namespace boost
    

    While it has been three years since this question and answer have been posted, I have not seen this discussed clearly in the Boost.Test documentation.

提交回复
热议问题