inline std::ostream& operator<<(std::ostream& p, const std::vector<unsigned int>& vector){
p << "[ ";
for(auto i:vector){
p << " "<< i << " ,";
}
p<< "]";
return p;
}
#define LOG_DEBUG_MESSAGE BOOST_LOG_SEV(my_logger::get(), debug)
std::vector<unsigned int> test {1, 2, 3};
LOG_DEBUG_MESSAGE << "test "<< test;
std::cout << test << std::endl;
Hello,
I overloaded my operator<< for a std::vector. When i use std::cout it works well, but with boost log i get following error:
boost/log/utility/formatting_ostream.hpp:710:19: error: cannot bind 'boost::log::v2_mt_posix::basic_formatting_ostream::ostream_type {aka std::basic_ostream}' lvalue to 'std::basic_ostream&&' strm.stream() << value;
/opt/gcc.4.9.1/include/c++/4.9.1/ostream:602:5: note: initializing argument 1 of 'std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&&, const _Tp&) [with _CharT = char; _Traits = std::char_traits; _Tp = std::vector]' operator<<(basic_ostream<_CharT, _Traits>&& __os, const _Tp& __x)
I have no idea why boost log is not working. It uses the same << operator or? On other examples with own classes it works well with overloading. I have no idea what I miss. Anyone has an idea how i can solve this error?
std::ostream
, which is why your code doesn't work. – Some programmer dude<<
operator in the std namespace and confirm if it compiles? – bobahoperator<<
as a templatetemplate<typename CharT, typename Traits> inline std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& p, //etc
. – user657267namespace std { signature here; }
std::ostream& std::operator<<() {}
– Kurt