std::basic_ostream<CharT,Traits>:: operator=
From cppreference.net
<
cpp
|
io
|
basic ostream
|
protected
:
basic_ostream & operator = ( const basic_ostream & rhs ) = delete ; |
(1) | |
|
protected
:
basic_ostream & operator = ( basic_ostream && rhs ) ; |
(2) | (C++11부터) |
1)
복사 할당 연산자는 protected로 선언되었으며 삭제되었습니다. 출력 스트림은
CopyAssignable
요구 사항을 만족하지 않습니다.
2)
이동 할당 연산자는 기본 클래스의 모든 데이터 멤버를
rdbuf()
를 제외하고
rhs
와 교환합니다. 마치
swap
(
*
rhs
)
를 호출하는 것처럼 동작합니다. 이 이동 할당 연산자는 protected로 선언되어 있습니다: 파생된 이동 가능 출력 스트림 클래스인
std::basic_ofstream
와
std::basic_ostringstream
의 이동 할당 연산자에 의해서만 호출되며, 이들은 관련된 스트림 버퍼를 올바르게 이동 할당하는 방법을 알고 있습니다.
매개변수
| rhs | - |
할당할
basic_ostream
객체
*
this
|
예제
이 코드 실행
#include <iostream> #include <sstream> #include <utility> int main() { std::ostringstream s; // std::cout = s; // ERROR: copy assignment operator is deleted // std::cout = std::move(s); // ERROR: move assignment operator is protected s = std::move(std::ostringstream() << 42); // OK, moved through derived std::cout << s.str() << '\n'; }
출력:
42
결함 보고서
다음의 동작 변경 결함 보고서들은 이전에 발표된 C++ 표준에 소급 적용되었습니다.
| DR | 적용 대상 | 게시된 동작 | 올바른 동작 |
|---|---|---|---|
| LWG 2067 | C++11 |
1. 오버로드
(1)
의 매개변수 타입은
basic_ostream&
2. 오버로드 (2) 의 매개변수 타입은 const basic_ostream && |
1.
const
추가됨
2. const 제거됨 |