UpCasting1 [C++] upcasting (업캐스팅) upcasting (업캐스팅) - 기반 클래스 타입의 포인터로 파생 클래스를 가리킬 수 있다. - 기반 클래스 타입의 참조로 파생 클래스를 가리킬 수 있다. class Shape { public: int color; }; class Rect : public Shape { public: int x, y, w, h; }; int main() { Rect rect; Rect* p1 = ▭ // ok int* p2 = ▭ // error. Shape* p3 = ▭ // ok Shape& r = rect; // ok. } main.cpp:18:18: error: cannot convert ‘Rect*’ to ‘int*’ in initialization Shape* p3 = ▭ .. 2021. 8. 27. 이전 1 다음