I am working on a project which is nested templates. How to refer to typename’s typename?
See examples below.
template<typename T>
class point1{
public:
T x, y;
point1(T v1, T v2):x(v1), y(v2){}
}
template<typename T>
class point2{
public:
T a, b;
point2(T v1, T v2):a(v1), b(v2){}
}
template<typename pointarray>
class coordinates{
public:
pointarray & _pp;
void printsum(){
using pointtype = typename pointarry::value_type;
// pointarray could be like vector<point1<int>>, deque<point2<double>>
// now pointtype could be point1 or point2
// there will be compiling issues in below.
auto intORdouble = pointtype::value_type;
intORdouble ssumm = 0;
}
}
The more I learned about template
in C++, the more complicated it seemed to be.
New contributor
taitai is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.