LearnThatStack Ace your next interview
C++ · question
Question 8 of 59

What is a pure virtual function, and how does it differ from a virtual one?

beginner
← All C++ questions
Re-explain

A pure virtual function is declared with = 0 and has no required implementation in the base. It says every concrete derived class must supply one.

struct Shape {
  virtual double area() const = 0;  // no body, derived classes must provide one
};  // Shape s; fails to compile, Shape is abstract

The difference from a plain virtual function is obligation. A virtual function ships a default that derived classes may replace. A pure virtual ships nothing to fall back on. So the compiler refuses to instantiate the class, and refuses any derived class that leaves it unimplemented.

Any class with at least one pure virtual is abstract. You use it as an interface: hold objects through a Shape pointer or reference. The compiler then proves that no half-finished type ever gets created.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

The diagram below the answer is the concept . Jump to it ↓

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

Saved in this browser - sign in to keep your review list.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Interview lens

Likely follow-ups, what you can say, and the weak answers to avoid.

Sign in free to open it Free account - the lens opens as soon as you're back.

Want a quick review of the fundamentals? See the C++ cheatsheet.

← Back to all C++ questions
Pro · $10/mo

51 of 59 C++ answers are in Pro.

Full answers, code samples, and AI explanations that go simpler or deeper. Cancel anytime.

  • Full answers + code
  • AI explanations, simpler or deeper
  • 1,000 AI credits / month
  • Cancel anytime