C++ If I write a function template and don’t request any instantiations of it, will any template functions be generated from it?

Viewed 203

just asking a question ive been pondering about in the last chapter of my textbook i read

"If I write a function template and don’t request any instantiations of it, will any template functions be generated from it?"

I believe its false because if you dont ask explicitly through an instantiation then the template cannot be created. Thoughts?

1 Answers

A class template by itself is not a type, or an object, or any other entity.

No code is generated from a source file that contains only template definitions. In order for any code to appear, a template must be instantiated: the template arguments must be provided so that the compiler can generate an actual class (or function, from a function template).

https://en.cppreference.com/w/cpp/language/templates

Related