How to overload the ostream operator << to make it work with log4cxx in C++?

前端 未结 3 1776
甜味超标
甜味超标 2020-12-19 01:50

Say I have a class A and an operator<< declared like so:

// A.h
class A
{
    // A stuff
};
std::ostream& operator<<(std::ostream& os, co         


        
3条回答
  •  感情败类
    2020-12-19 02:48

    Alan's suggestion of putting the user-defined operator in the std namespace works. But I prefer putting the user-defined operator in the log4cxx::helpers namespace, which also works. Specifically,

    namespace log4cxx { namespace helpers {
        ostream& operator<<(ostream& os, const A& a);
    } }
    

提交回复
热议问题