在模板类的头文件中包含.cpp文件 [英] Including .cpp file in the header file for a template class

查看:153
本文介绍了在模板类的头文件中包含.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.

这篇关于在模板类的头文件中包含.cpp文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆