class Empty {};
// 위 코드는 아래 코드와 동일하게 처리됨.
class Empty
{
public:
Empty() { ... } // 기본 생성자 (default constructor)
Empty(const Empty& rhs) { ... } // 복사 생성자 (copy constructor)
~Empty() { ... } // 소멸자 (destructor)
// 소멸자가 가상(virtual)인지 여부는 아래를 참조
Empty& operator=(const Empty& rhs) { ... } // 복사 할당 연산자 (copy assignment operator)
}
Empty e1; // default constructor 호출
Empty e2(e1); // copy constructor 호출
e2 = e1; // copy assignment operator 호출
template<typename T>
class NamedObject {
public:
NamedObject(std::string& name, const T& value);
... // 이전과 동일하게 복사 할당 연산자는 선언하지 않았다고 가정합니다.
private:
std::string& nameValue; // 참조로 변경됨
const T objectValue; // const로 변경됨
};
std::string newDog("Persephone");
std::string oldDog("Satch");
NamedObject<int> p(newDog, 2);
NamedObject<int> s(oldDog, 36);
p = s; // p의 멤버 데이터에 대해
const 멤버 를 포함하는 클래스에 대해서도 비슷하게 동작💫Things to Remember
컴파일러는 클래스의 기본 생성자, 복사 생성자, 복사 할당 연산자, 그리고 소멸자를 암묵적으로 생성할 수 있다.