가장 많이 묻는 면접 질문과 답변 & 온라인 테스트
면접 준비, 온라인 테스트, 튜토리얼, 라이브 연습을 위한 학습 플랫폼

집중 학습 경로, 모의고사, 면접 준비 콘텐츠로 실력을 키우세요.

WithoutBook은 주제별 면접 질문, 온라인 연습 테스트, 튜토리얼, 비교 가이드를 하나의 반응형 학습 공간으로 제공합니다.

Chapter 6

Inheritance, Polymorphism, Virtual Functions, and Abstract Classes

Understand object-oriented extension in C++ using inheritance, overriding, runtime polymorphism, and abstract interfaces.

Inside this chapter

  1. Inheritance Basics
  2. Virtual Functions and Dynamic Dispatch
  3. Abstract Classes
  4. Composition Versus Inheritance
  5. Destructor Warning
  6. Real-World Usage Snapshot

Series navigation

Study the chapters in order for the clearest path from C++ basics to modern ownership, templates, concurrency, performance, and production-ready engineering practices. Use the navigation at the bottom to move smoothly through the full series.

Tutorial Home

Chapter 6

Inheritance Basics

class Animal {
public:
    virtual void speak() const {
        std::cout << "Animal sound\n";
    }
    virtual ~Animal() = default;
};

class Dog : public Animal {
public:
    void speak() const override {
        std::cout << "Woof\n";
    }
};

Inheritance models an is-a relationship. It is useful when subtype behavior genuinely extends a base abstraction, but overusing inheritance can create rigid designs.

Chapter 6

Virtual Functions and Dynamic Dispatch

Virtual functions enable runtime polymorphism, meaning the correct overridden method is chosen based on the actual object type, even through a base pointer or reference.

Chapter 6

Abstract Classes

class Shape {
public:
    virtual double area() const = 0;
    virtual ~Shape() = default;
};

Pure virtual functions make a class abstract. This is useful for defining interfaces that different concrete classes must implement.

Chapter 6

Composition Versus Inheritance

One of the most important design lessons in C++ is that composition is often safer and more flexible than inheritance. Inheritance is powerful, but it should be used intentionally, not automatically.

Chapter 6

Destructor Warning

Base classes intended for polymorphic use should typically have virtual destructors. Otherwise deleting a derived object through a base pointer can cause incomplete cleanup and undefined behavior.

Chapter 6

Real-World Usage Snapshot

Polymorphism appears in graphics systems, plugin architectures, device abstraction, parser hierarchies, GUI frameworks, and many extensible libraries. Strong C++ developers know when runtime polymorphism is the right tool and when simpler alternatives are better.

Copyright © 2026, WithoutBook.