テンプレート化されたクラスを作成しましたが、正常に動作します:
(私はopenCVライブラリを使用しているので、cv::Matタイプの行列があります)
template < class T, T V >
class MatFactory
{
private:
const T static VALUE = V;
public:
void create(/* some args */)
{
cv::Mat M;
// filling the matrice with values V of type T
// loop i,j
M.at<T>(i,j) = V;
return M;
}
};
しかし、コードの後半では、いくつかのインデックス (i,j) で行列 M の要素を取得する必要があります。しかし、どうすればタイプ T を知ることができますか?
MatFactory<int, 1> MF;
// getting object
cv::Mat m = MF.create();
// then I need to get some value (with `.at<>` method)
int x = m.at<int>(2,3);
// But, it means I should every time explicitly declare INT type
// Can I somehow get the type, that was passed to template factory
// Than i'll write something like this:
T x = m.at<T>(2,3);
// How to get T from the deferred template?