Sunday 28 May 2017

c++ - Why should the implementation and the declaration of a template class be in the same header file?





Why should the implementation and the declaration of a template class be in the same header file? Could any of you explain it by example?


Answer



The compiler needs to have access to the entire template definition (not just the signature) in order to generate code for each instantiation of the template, so you need to move the definitions of the functions to your header.



For more details read about The Inclusion Model.



No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...