A mysterious compilation error: cannot convert from 'const boost::shared_ptr<T>' to 'const boost::shared_ptr<T>'
        Posted  
        
            by 
                Stephane Rolland
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Stephane Rolland
        
        
        
        Published on 2012-11-29T16:55:04Z
        Indexed on 
            2012/11/29
            17:03 UTC
        
        
        Read the original article
        Hit count: 525
        
I wanted to protect the access to a log file that I use for multithreaded logging with boostlog library.
I tried this stream class
class ThreadSafeStream
{
public:
    template <typename TInput>
    const ThreadSafeStream& operator<< (const TInput &tInput) const
    {
         // some thread safe file access    
         return *this;
    }
};
using it this way (text_sink is a boostlog object):
    //...
m_spSink.reset(new text_sink); 
text_sink::locked_backend_ptr pBackend = m_spSink->locked_backend();
const boost::shared_ptr< ThreadSafeStream >& spFileStream = boost::make_shared<ThreadSafeStream>();
pBackend->add_stream(spFileStream); // this causes the compilation error
and I get this mysterious error: cannot convert from 'const boost::shared_ptr<T>' to 'const boost::shared_ptr<T>'
the whole compile error:
Log.cpp(79): error C2664: 'boost::log2_mt_nt5::sinks::basic_text_ostream_backend<CharT>::add_stream' : cannot convert parameter 1 from 'const boost::shared_ptr<T>' to 'const boost::shared_ptr<T> &'
1>          with
1>          [
1>              CharT=char
1>          ]
1>          and
1>          [
1>              T=ThreadSafeStream
1>          ]
1>          and
1>          [
1>              T=std::basic_ostream<char,std::char_traits<char>>
1>          ]
1>          Reason: cannot convert from 'const boost::shared_ptr<T>' to 'const boost::shared_ptr<T>'
1>          with
1>          [
1>              T=ThreadSafeStream
1>          ]
1>          and
1>          [
1>              T=std::basic_ostream<char,std::char_traits<char>>
1>          ]
1>          No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
I suspect that I am not well defining the operator<<()... but I don't find what is wrong.
© Stack Overflow or respective owner