Introduction
Explore how to solve factory method challenges in C++17 by using if constexpr to conditionally compile code and handle variable constructor arguments safely, improving flexibility and avoiding compilation errors.
We'll cover the following...
We'll cover the following...
The Problem
In item 18 of Effective Modern C++ Scott Meyers described a method called makeInvestment:
There’s a factory method that creates derived classes of Investment, and the main advantage is
that it supports a variable number of arguments!
For example, here are the proposed derived types:
The code from the book was too idealistic, and it worked until ...