I am using CPPUnit to test a class in my program. This class (SCriterionVal) is somewhat unique because it has conversion operators for a lot of types (it's essentially a dynamic type value class). When I compile test cases that test it using CPPUNIT_ASSERT_EQUAL(), I get compilation errors about "operator<< is ambiguous" from one of the CPPUnit header files. It appears that it is instantiating the assertion_traits struct with my type, and that struct has a toString() method that works by using operator<< on an OStringStream.
I assume it's ambiguous instead of an error because of the various conversions available on SCriterionVal, some of which have defined operator<< (such as the built in types). In an attempt to rectify this situation, I created a non-member function in the header for SCriterionVal with this signature:
ostream &operator<<(ostream &stream, SCriterionVal val);
I figured because the signature should be an exact match, it will resolve the ambiguity. No such luck. What am I doing wrong here? I suppose I can specialize the template for assertion_traits for my type, but I was hoping to be able to solve the more general problem of providing a way to put my class into a stream, rather than just catering to the test framework.