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()
이렇게해도 상관없던데 차이가 뭔가요 ???
클래스정의는 소괄호 안해도되지않나요? 멤버함수 사용할때만 소괄호 하는거 아니었나요 ?
이거 답변하면 프갤 상위 1%
혹시 아시나요 ?
해당 댓글은 삭제되었습니다.
소괄호의 유무에 대한 차이는 뭔가요 ㅠㅠ? 힙 스택 이런건 제가 아직 컴구를 깊이안배워서 ..
제가 난독증이 있어서 질문을 잘못읽었네요
이걸 읽으세요 :
https://stackoverflow.com/questions/620137/do-the-parentheses-after-the-type-name-make-a-difference-with-new
감사합니다!