Template Constraints

You will be introduced to the template constraints in this lesson.


The fact that templates can be instantiated with any argument yet not every argument is compatible with every template brings an inconvenience. If a template argument is not compatible with a particular template, the incompatibility is necessarily detected during the compilation of the template code for that argument. As a result, the compilation error points at a line inside the template implementation.

Let’s see this by using useSoundEmittingObject() with a type that does not support the object.emitSound() call:

Get hands-on with 1000+ tech skills courses.