You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
classShape{
public:virtualvoiddraw() const = 0; // 순수 가상 함수virtualvoiderror(const std::string& msg); // 단순 가상 함수intobjectID() const; // 비가상 함수
};
classRectangle: publicShape{};
classEllipse: publicShape{};
Shape a; // 에러. 인스턴스를 만들 수 없음
Shape는 순수 가상 함수인 draw 함수 때문에 인스턴스를 만들 수 없는 추상 클래스이다.
Shape의 파생 클래스(Rectangle, Ellipse)만 인스턴스를 만들 수 있다.
Shape가 클래스로부터 파생된 클래스에 미치는 영향은 절대적이다.
멤버 함수 인터페이스는 항상 상속되기 때문이다.
각 함수에 대한 설명
draw 함수(순수 가상 함수)
순수 가상 함수를 선언하는 목적은 파생 클래스에게 함수의 인터페이스만을 물려주려는 것이다.