2012-11-29 1 views
0

부스트 로그 라이브러리로 멀티 스레드 로깅 할 때 사용하는 로그 파일에 대한 액세스를 보호하려고합니다.신비한 컴파일 오류 : 'const boost :: shared_ptr <T>'에서 'const boost :: shared_ptr <T>'으로 변환 할 수 없습니다.

//... 
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 

나는이 신비 오류 얻을 : cannot convert from 'const boost::shared_ptr<T>' to 'const boost::shared_ptr<T>'

전체 컴파일을

나는 (text_sink는 boostlog 개체입니다) 이런 식으로 사용이 스트림 클래스

class ThreadSafeStream 
{ 
public: 
    template <typename TInput> 
    const ThreadSafeStream& operator<< (const TInput &tInput) const 
    { 
     // some thread safe file access  
     return *this; 
    } 
}; 

시도 오류 :

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 

나는 연산자를 잘 정의하지 않는다고 생각한다. < <() ... 그러나 나는 틀린 것을 발견하지 못했다. (!) void add_stream(shared_ptr<stream_type> const& strm); 당신이 완전히 무관있는 ThreadSafeStream에에게 shared_ptr을 제공하는 동안 presuably pBackend->add_streamshared_ptrostream에 예상되는 오류 메시지에서

+0

실제로 어떤 줄에서 오류가 발생합니까? 'add_stream'에 대한 호출입니까? 그렇다면 메소드 서명을 제공 할 수 있습니까? –

+0

'pBackend-> add_stream (spFileStream);'문제를 일으킨다. 나는 프로토 타입을 찾고있어 질문에 넣을거야. –

답변

2

typedef std::basic_ostream<target_char_type> stream_type;과 :

는 addStream의 프로토 타입입니다 유형. 대체로 ThreadSafeStream과 작동하는 오버로드 된 add_stream 메서드를 만들어야합니다.

+1

내 필요에 맞게 부스트 로그 코드를 수정할 수는 없지만 클래스'ThreadSafeStream'에서'std :: basic_ostream'을 상속해야합니다. –

관련 문제