在模板类的头文件中包含.cpp文件
我知道模板类的定义和实现应该在同一个头文件。但我在学校上学的有点不同。
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.
我会在头文件中定义模板类,在头文件的末尾, do #includeMyFile.cpp,它包含模板类的实现。
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?"
一般来说不是,这是一个很常见的技术。但问题是 .cpp
文件扩展名,这将影响许多IDE和构建系统,将其视为常规源文件。更常用的扩展名为 .tcc
, .tpc
。
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
.