简体   繁体   中英

Including .cpp file in the header file for a template class

I do know that template class's definition and implementation should be on the same header file. But I was taught a bit differently at school.

I'll have the template class's definition in the header file, and at the end of the header file, I'll do #include "MyFile.cpp", which contains the implementation of the templated class.

Is this bad programming practice?

"Is this bad programming practice?"

In general not and it's a very common technique. But the problem is the .cpp file extension, that would affect many IDEs and build systems to consider it as a regular source file. More commonly used extensions are .tcc , .tpc .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM