Template Instantiation

In this lesson, we'll learn about template instantiation.

We'll cover the following

Template Instantiation

Templates can be implicitly and explicitly instantiated. Implicit instantiation means automatically and explicit means manually.


std::vector<int> vec{};
bool isSmaller<double>(fir, sec);
bool isSmaller(fir, sec);


template class std::vector<int>;
template bool std::vector<double>::empty() const;
template bool isSmaller<double>(double, double); 
template bool isSmaller(double, double);

Lazy Evaluation

When a class is instantiated, only the method declarations are available.

The definition of a method is only instantiated when it is used.

It is not necessary that all methods of class templates are valid for the template arguments. You can only use the methods, which are valid for a given instantiation.

Get hands-on with 1000+ tech skills courses.

Learn to code, grow your skills, and succeed in your tech interview