C++ upcasting
![[C++] upcasting](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdna%2Fb4g8Bs%2FbtqzZ25yhDd%2FAAAAAAAAAAAAAAAAAAAAABtTGz1J_zQOeOjV1A2FvVxFPLlKVGmlXl13eR5S2adU%2Fimg.png%3Fcredential%3DyqXZFxpELC7KVnFOS48ylbz2pIh7yKj8%26expires%3D1756652399%26allow_ip%3D%26allow_referer%3D%26signature%3D98TRvQDvcQ1faxMU%252BMGpiw2iyWs%253D)
[C++] upcasting
1. 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 = ▭ // ?? Shape& r = rect; // ?? } main함수를 살펴보자 1. Rect* p1 = ▭ - 서로 똑같은 타입으로 아무 문제 없이 ok. 2. int* p2 = ▭ - 이건 완벽히 다른 타입으로 error / 리인터프리터 캐스팅을 사용하면 가능 3. Shape* p3 = ▭ - 앞에 포인터가 Rect는 아니지만 기..