다음을 통해 공유


개체 (RAII) 리소스를 소유합니다.

자체 리소스 개체를 있는지 확인 하십시오.이 원칙은 라고도 하는 "자원 획득 초기화" 것입니다 또는 "RAII."

예제

모든 "새" 개체 생성자 인수로 (거의 항상 unique_ptr)를 소유 하 고 다른 명명 된 개체에 전달 합니다.

void f() {
  unique_ptr<widget> p( new widget(…) );
  my_class x( new widget() );
  …
} // automatic destruction and deallocation for both widget objects
  // automatic exception safety, as if “finally { p->dispose(); x.w.dispose(); }”

항상 즉시 모든 새 자원을 소유 하 고 다른 개체에 전달 합니다.

void g() {
  other_class y( OpenFile() );
  …
} // automatic closing and release for file resource
  // automatic exception safety, as if “finally { y.file.dispose(); }”

참고 항목

기타 리소스

C + + (현대 C++)를 다시 시작

C + + 언어 참조

표준 C++ 라이브러리 참조