I think I've found the answer which is given from OpenCV documentation. They call the technique "Class Trait" by the use of DataType class.
it's like:
Mat mtx = Mat::zeros(vect.size(), vect[0].size(), DataType<NumType>::type);
For example:
template <class NumType>
cv::Mat Vect2Mat(std::vector<std::vector<NumType>> vect)
{
cv::Mat mtx = cv::Mat::zeros(vect.size(), vect[0].size(), cv::DataType<NumType>::type);
//Mat mtx;
// copy data
for (int i=0; i<vect.size(); i++)
for (int j=0; j<vect[i].size(); j++)
{
mtx.at<NumType>(i,j) = vect[i][j];
//cout << vect[i][j] << " ";
}
return mtx;
}