C++:テンプレート関数の定義と宣言の分離;
591 ワード
テンプレート関数やテンプレートクラスの定義は一般的に宣言とともにヘッダファイルに存在することが知られていますが、そうすると内部実装が露呈し、定義と宣言を分離する方法はありませんか?
答えは:あります;
答えは:あります;
: test.h;
class test
{
template void f(T &val);
}
cpp : test.cpp;
#include "test.h"
template
void test::f(T &val){
.....
}
// , ; : cpp ;
template void test::f(int val);
template void test::f(double val);
, , ;