I have a class template in myclass.hpp:
template<class T, class P>
class myclass
{
....
};
In my main.cc I create an object of the class:
myclass<int, double> mc;
otherfunc<myclass>(mc);
In some other header file header1.hpp:
template<class MyClass>
void otherfunc(MyClass const &mc)
{
/* Access through 'mc' the underlying template parameters T and P*/
}
How can I access the template parameter T and P in header1.hpp?
How can I access the template parameter T and P in header1.hpp?
Provide public type definitions in your class myclass:
template<class T, class P>
class myclass
{
public:
typedef T T_type;
typedef P P_type;
....
};
Thus you can access those types as
typename myclass::T_Type x;
typename myclass::P_Type y;
elsewhere.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With