2017-03-18 1 views
0

포인터 뒤에있는 값에 대한 참조를 원합니다.포인터 뒤의 값에 대한 참조

class UnicastCall { 
protected: 
    std::fstream *m_stream_attachement_destination_; 
... 
public: 
auto GetStreamAttachementDestination_AsPointer() -> decltype(m_stream_attachement_destination_) 
    { return m_stream_attachement_destination_; } //THIS WORKS 
auto GetStreamAttachementDestination_AsReference() -> decltype(*m_stream_attachement_destination_) & 
    { return *m_stream_attachement_destination_; } //IS THIS CORRECT? 
.... 
}; 

그러나 오류가 발생합니다.

error: use of deleted function 'std::basic_fstream<_CharT, _Traits>::basic_fstream(const std::basic_fstream<_CharT, _Traits>&) [with _CharT = char; _Traits = std::char_traits<char>]' 
auto fs = concrete_call->GetStreamAttachementDestination_AsReference(); 

답변

2

허용되지 않는 std::fstream을 복사하려고합니다.

오류가 수업에 있지 않지만 의 전화 사이트에 있습니다. auto fs = ...은 참조를 만들지 않지만 복사 생성자를 호출하려고 시도합니다. auto은 이 아닌 std::fstream 만 대체합니다.

이 대신보십시오 :

auto& fs = concrete_call->GetStreamAttachementDestination_AsReference(); 
+0

좋은! 편집하고 일한다. –