Question: Suppose you've written a large C++ program that makes heavy use of templates, and that those templates are all written in header files. What effect

 Suppose you've written a large C++ program that makes heavy use

Suppose you've written a large C++ program that makes heavy use of templates, and that those templates are all written in header files. What effect would you expect this tendency to have on how long it takes to compile this large program, relative to an equivalent program that made no use of templates? Why?

We've discussed why it's so often the case that we write C++ templates in header files rather than source files. Let's explore a couple of aspects of that tendency, by answering two questions about it. Declaring function templates separately from writing their bodies Suppose you've decided to write a function template that you expect to use in many different source files. Suppose, further, that you haven't followed the basic advice of writing C++ templates in header files, but have instead done the following: Written only a declaration of the function template in a header file x.hpp (i.e., all you wrote in the header file is template and then the function's signature). Written the function template, including its body, in the corresponding source file x.cpp. Now suppose that you've written a separate source file, y.cpp, in which you've written #include "x.hpp" near the top and then instantiated the function template by calling it, and that your call to the function template is a legal instantiation (i.e., it has the right number of template parameters, if specified, and they're compatible with any constraints introduced within the template)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!