개체지향 프로그래밍2
복사(COPY) 생성자
// Vector.h
class Vector
{
public:
Vector(const Vector& other); // 복사 생성자
private:
int mX;
int mY;
}
// Vector.cpp
Vector::Vector(const Vector& other)
: mX(other.mx)
, mY(other.mY)
{
}
Vector a;
Vector b(a);암시적(implicit) 복사 생성자

클래스에 포인터 형 변수가 있다면?



사용자가 만든 복사 생성자
연산자 오버로딩


연습문제.1 Vector의 operator+() 연산자를 오버로딩해보자
연산자 오버로딩 시 문제점
전역 함수로써 연산자 오버로딩의 문제를 해결하자
연산자 오버로딩과 const
연산자 오버로딩을 남용하지 말아라!
연산자 오버로딩에서 특별한 operator=
암시적 함수들을 제거하는 법!
Last updated



