Skip to Content
Hands-On Design Patterns with C++
book

Hands-On Design Patterns with C++

by Fedor G. Pikus
January 2019
Intermediate to advanced
512 pages
14h 5m
English
Packt Publishing
Content preview from Hands-On Design Patterns with C++

Chapter 13

  • Why does C++ not allow a virtual constructor?

There are several reasons, but the simplest is that the memory must be allocated in the amount sizeof(T), where T is the actual object type, and the sizeof() operator is constexpr (a compile-time constant).

  • What is the Factory pattern?

The Factory pattern is a creational pattern that solves the problem of creating objects without having to explicitly specify the type of the object.

  • How can we use the Factory pattern to achieve the effect of a virtual constructor?

While in C++ the actual type has to be specified at construction point, the Factory pattern allows us to separate the point of construction from the place where the program has to decide what object to construct and to ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Structural Design Patterns in Modern C++

Structural Design Patterns in Modern C++

Umar Lone

Publisher Resources

ISBN: 9781788832564Supplemental Content