2017-02-06 1 views
-1

모든 플랫폼에서 어떤 기능 버전 (myfunc2 또는 myfunc3)이 올바른지 확인하십시오.ios의 올바른 사용

ostream &myfunc1(ostream &os) const { 
    // 
    return os; 
} 
ostream &myfunc2(ostream &os) const { 

    os << myfunc1(os); 
} 

ostream &myfunc3(ostream &os) const { 

    os << myfunc1(os).rdbuf(); 
} 
+0

'myfunc2'와'myfunc3' 각각에서'return' 문이 누락 되었습니까? –

답변

2

당신은 streambuf의 기본 버퍼를 액세스하는 스트림의 rdbuf()에 액세스 할 필요가 없습니다.

개념적으로 ostreamstreambuf의 프런트 엔드입니다. myfunc3에서 수행중인 작업은 ostream에서 인터페이스를 건너 뛰고 streambuf에서 rdbuf에 직접 액세스하는 것입니다.

이것은 수행 할 수 있지만 드문 경우입니다. myfunc2에 붙여서, 그것을하는 보통 방법이다.