This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #include <iostream> | |
| #include <vector> | |
| #include <string> | |
| using namespace std; | |
| namespace Item17 { | |
| //new로 생성한 객체를 스마트 포인터에 저장하는 코드는 별도의 한 문장으로 만들자 | |
| class Widget{}; | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #include <iostream> | |
| #include <vector> | |
| #include <string> | |
| using namespace std; | |
| namespace Item16 { | |
| //new 및 delete를 사용할 때는 형태를 반드시 맞추자 | |
| void Func() { | |
| std::string *stringArr = new std::string[100]; | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #include <iostream> | |
| #include <vector> | |
| #include <string> | |
| using namespace std; | |
| namespace Item15 { | |
| //자원 관리 클래스에서 관리되는 자원은 외부에서 접근할 수 있도록 하자 | |
| class Investment {}; | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | template<class _Ty> | |
| _NODISCARD constexpr remove_reference_t<_Ty>&& | |
| move(_Ty&& _Arg) noexcept | |
| { // forward _Arg as movable | |
| return (static_cast<remove_reference_t<_Ty>&&>(_Arg)); | |
| } | |
| /* | |
| std::move 는 사실상 타입변환. 메모리 상에서는 아무 일도 일어나지 않는다. | |
| return (static_cast<remove_reference_t<_Ty>&&>(_Arg)); | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | int lv1 = 16; //좌측값 | |
| 009CBD7D mov dword ptr [lv1],10h | |
| int& lv2 = lv1; //좌측값 레퍼런스 -> lv1의 주소 저장 | |
| 009CBD84 lea eax,[lv1] | |
| 009CBD87 mov dword ptr [lv2],eax | |
| int&& rv1 = 5; //우측값 레퍼런스 -> 여기서 5를 붙잡아두기 위해 스택메모리에 따로 공간이 만들어진다. | |
| 009CBD8A mov dword ptr [ebp-78h],5 | |
| 009CBD91 lea eax,[ebp-78h] | |
| 009CBD94 mov dword ptr [rv1],eax | |
| //rv1 은 따로 할당된 메모리의 주소를 참조 | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | class ConstructorTest { | |
| public: | |
| ConstructorTest() | |
| { cout << "Default Constructor" << endl; } | |
| ConstructorTest(int v) : value(v) | |
| { cout << "Constructor With Int Parameter" << endl; } | |
| ConstructorTest(const ConstructorTest& rhs) : value(rhs.value) | |
| { cout << "Copy Constructor" << endl; } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | //자원 관리 클래스의 복사 동작에 대해 진지하게 고찰하자 | |
| class Lock { | |
| public: | |
| explicit Lock(mutex *pm) : mutexPtr(pm) { mutexPtr->lock(); } //자원 획득 시 뮤텍스 잠금 | |
| ~Lock() { mutexPtr->unlock(); } //소멸 시 뮤텍스 잠금 해제 | |
| private: | |
| mutex *mutexPtr; | |
| }; | |
| void doSomething() { | 
NewerOlder