✏️ 상속 예시
#include <iostream>
#include <string>
using namespace std;
/*
Red:(3,4)
*/
class Shape {
private:
int x, y; //(x,y) 좌표값
int type; //0. 미지정, 1. 원, 2. 사각형
public:
Shape() { type = 0; }
void set(int x, int y) {
this->x = x; this->y = y;
}
void showPoint() {
cout << "(" << x << "," << y << ")" << endl;
}
};
class Circle : public Shape {
string color;
public:
void setColor(string color) { this->color = color;}
void showCircle();
};
void Circle::showCircle() {
cout << color << ":";
showPoint();
}
int main() {
Shape p;
Circle cp;
cp.set(3, 4);
cp.setColor("Red");
cp.showCircle();
}