1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <iostream>
using namespace std;
 
class Shape {
protected:
    int x, y;
 
public:
    virtual void draw() {
        cout << "Shape Draw";
    }
    void setOrigin(int x, int y) {
        this->x = x;
        this->y = y;
    }
};
 
class Rectangle : public Shape {
private:
    int width, height;
public:
    void setWidth(int w) {
        width = w;
    }
    void setHeight(int h) {
        height = h;
    }
    void draw() {
        cout << "Rectangle Draw" << endl;
    }
};
 
class Circle : public Shape {
private:
    int radius;
public:
    void setRadius(int r) {
        radius = r;
    }
    void draw() {
        cout << "Circle Draw" << endl;
    }
};
 
class Triangle : public Shape {
private:
    int base, height;
public:
    void setBase(int b) {
        base = b;
    }
    void setHeight(int h) {
        height = h;
    }
    void draw() {
        cout << "Triange Draw" << endl;
    }
};
 
int main()
{
    Shape* arrayOfShape[3];
 
    arrayOfShape[0] = new Rectangle;
    arrayOfShape[1] = new Triangle;
    arrayOfShape[2] = new Circle();
    for (int i = 0; i < 3; i++) {
        arrayOfShape[i]->draw();
    }
}
cs





64,65,66 에서


new Rectangle() , new Triangle(), new Circle()


이렇게해도 상관없던데 차이가 뭔가요 ???


클래스정의는 소괄호 안해도되지않나요? 멤버함수 사용할때만 소괄호 하는거 아니었나요 ?