virtual 호출은 정적 타입이 아니라 실제 객체의 override로 간다
호출 코드는 Base 인터페이스만 보지만, virtual 함수는 런타임 객체의 vtable을 따라 실제 구현을 찾는다.
| 호출 상황 | 정적 타입 | 실제 객체 | 호출 결과 |
|---|---|---|---|
| Shape s; s.draw() | Shape | Shape | Shape::draw |
| Shape* p = &circle; p->draw() | Shape* | Circle | Circle::draw |
| Shape& r = rect; r.draw() | Shape& | Rectangle | Rectangle::draw |
| delete Shape* p | Shape* | Derived | virtual 소멸자가 있어야 Derived 소멸자까지 호출 |
| virtual 누락 | Shape* | Circle | 정적 타입 기준 Shape::draw로 묶일 위험 |