April 2017
Beginner to intermediate
394 pages
9h 16m
English
Using a virtual constructor can be very powerful. The biggest benefit is that we can now treat classes as if they had first class status. We can make copies of an object without knowing the exact type of the object. We can use the Prototype pattern in our level editor example, but we could also use it in our game. Anytime we need to make a copy without truly knowing the type, we can use this pattern. As we said before, C++ is a statically typed language, meaning the compiler will make sure we are using the correct types at compile time. This static type checking helps us write safer code.
By using Dynamic Factories and virtual constructors, we are bypassing this type checking a little. The compiler is ...
Read now
Unlock full access