private template functions

六眼飞鱼酱① 提交于 2019-12-05 00:13:44

When a function template is used in a way that triggers its instantiation, a compiler(at some point) needs to see that template's definition. And that is the reason, templates are usually implemented inside a header file using inline finctions.

So as long as the above rules gets followed it is still okay to have interface and implementation separated in header and source files.


Reference:
C++03 standard, § 14.7.2.4:

The definition of a non-exported function template, a non-exported member function template, or a non-exported member function or static data member of a class template shall be present in every translation unit in which it is explicitly instantiated.

Unless your private member function template is used by member functions that are defined inline within the class definition, I see nothing wrong with this approach. On the contrary, I think that the less dependencies creep into your header files, the better.

This will work as long as you enforce the convention of always providing each class's implementation in a single source file.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!