I’ve created a templated class, and it works fine:
( I’m using openCV library, so I have cv::Mat type of matrices)
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;
}
};
But later in code, I need to get an element of matrix M at some indexes (i,j). But how do I know the type 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?
Just add a
typemember to yourMatFactory:Note that non-type template arguments are rather limited. In particular, floating point types are not allowed (thinking of it this may have been changed with C++2011).