This question has already been answered:
- To render the template class method in .cpp 3 responses
Is it possible to implement a template in cpp and not in the h file?
This question has already been answered:
Is it possible to implement a template in cpp and not in the h file?
A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .
In general, you can implement a template in any desired file, but remember that [parameterized] definitions of functions and template classes should be visible wherever they are used (specialized, instantiated).
If you use your template in only one translation unit (in one .cpp file) and nowhere else, then please - implement it in this .cpp file for health.
And if your template is used in several different translation units, then your .cpp file will still have to be included via #include wherever it is needed, exactly as is done with the .h files.
For this reason, traditionally, the entire implementation of the template class, including its method definitions, is placed in the .h file. In the .cpp file there are only definitions of explicitly specialized methods (explicit specialization), if any.
(That is, the answer is the question that you actually tried to ask - no, you can not.)
Source: https://ru.stackoverflow.com/questions/620747/
All Articles