【发布时间】:2018-09-17 13:41:42
【问题描述】:
我在 myclass.hpp 中有一个类模板:
template<class T, class P>
class myclass
{
....
};
在我的 main.cc 中,我创建了一个类的对象:
myclass<int, double> mc;
otherfunc<myclass>(mc);
在其他一些头文件header1.hpp中:
template<class MyClass>
void otherfunc(MyClass const &mc)
{
/* Access through 'mc' the underlying template parameters T and P*/
}
如何访问 header1.hpp 中的模板参数 T 和 P?
【问题讨论】:
-
otherfunc<myclass>(mc)对给定的otherfunc声明无效。你可以使用otherfunc(mc)(让扣除发生)或otherfunc<myclass<int, double>>(mc)。
标签: c++ templates class-template