我有一个类:私人模板功能
章
class C {
private:
template<int i>
void Func();
// a lot of other functions
};
C.cpp
// a lot of other functions
template<int i>
void C::Func() {
// the implementation
}
// a lot of other functions
我知道,这不是最好的主意移动模板实现在CPP文件(因为它不会从其他cpp中看到,其中可能包含带有模板声明的标题)。
但私人功能呢?任何人都可以告诉我,在.cpp文件中是否存在实现私有模板函数的缺点?
http://stackoverflow.com/questions/4315969/where-to-define-c-class-member-template-function-and-functors-that-instantiate/4316020#4316020 –
虽然这个问题在技术上由Als和Nicola回答,对我来说,这只是引发了一个问题,为什么你根本没有成为会员模板。将它作为cpp文件(的未命名名称空间)中的免费函数模板不是更好吗?我发现,随着时间的推移,我越来越少地使用私有成员函数,越来越多地使用类的实现文件(的未命名名称空间)中的自由函数。 – sbi