I’m a C++ newbie. I’ve tried to set up NetBeans and run a c++ program in my MacBook Air via virtual machine (UTM) lately. It works well in my company's Linux desktop, but somehow it just doesn’t work in my virtual Linux. The source code is the same in these two platforms, but they have different compilation result. One is fine, and the other shows the error message below.
error: no match for ‘operator<<’
I was wondering if it is due to the version mismatch or something similar of these two Linux environment. By the way, the author of this program has left the company, so I am doing my best to understand the his code. I’ve seen several posts here about this exactly the same issue, but it seems none of those solutions can work with my situation where this source code works well in one Linux while it doesn’t work in another one.
Below is the error message and relevant source codes. Could you please help me look into them? Thanks a lot!
Source code:
class logger
{
public:
typedef std::ostringstream collector_stream_type;
private:
collector_stream_type _os;
log_levels _messageLevel;
public:
logger(const logger & r) : _messageLevel(r._messageLevel)
{
if ( do_log() ) _os << r._os; // this is where the error occurs.
}
}
Error / Warning message from NetBeans
In file included from
- error: no match for ‘operator<<’ (operand types are ‘MySoftware::log::logger::collector_stream_type’ {aka ‘std::__cxx11::basic_ostringstream’} and ‘const collector_stream_type’ {aka ‘const std::__cxx11::basic_ostringstream’})
- note: cannot convert ‘r.MySoftware::log::logger::_os’ (type ‘const collector_stream_type’ {aka ‘const std::__cxx11::basic_ostringstream’}) to type ‘const std::error_code&’
- note: ‘const collector_stream_type’ {aka ‘const std::__cxx11::basic_ostringstream’} is not derived from ‘const std::complex<_Tp>’
- note: cannot convert ‘((MySoftware::log::logger*)this)->MySoftware::log::logger::_os’ (type ‘MySoftware::log::logger::collector_stream_type’ {aka ‘std::__cxx11::basic_ostringstream’}) to type ‘std::byte’
- note: candidate: ‘operator<<(int, int)’ (built-in)
- note: ‘const collector_stream_type’ {aka ‘const std::__cxx11::basic_ostringstream’} is not derived from ‘const std::__shared_ptr<_Tp, _Lp>’
- note: deduced conflicting types for parameter ‘_CharT’ (‘char’ and ‘std::__cxx11::basic_ostringstream’...