S
shuisheng
Dear All,
Assume I have a class template of multi-dimension point as follows:
template<int nDim>
class Point
{
public:
double GetCoordinate(int iDim)
{
return m_coordinate[iDim];
}
private:
double m_coordinate[nDim];
};
But for different dimetion points, their constructor are different such
as
Point<1>(double);
Point<2>(double, double);
Point<3>(double, double, double);
So we can specialize the classes to implement the constructors. But
this way need to rewrite the common code such as "double
GetCoordinate(int)". Is there any easy way to implement them? What I
mean is that just specializing those constructors rather than
specialize the total class.
Thanks for your help!
Shuisheng
Assume I have a class template of multi-dimension point as follows:
template<int nDim>
class Point
{
public:
double GetCoordinate(int iDim)
{
return m_coordinate[iDim];
}
private:
double m_coordinate[nDim];
};
But for different dimetion points, their constructor are different such
as
Point<1>(double);
Point<2>(double, double);
Point<3>(double, double, double);
So we can specialize the classes to implement the constructors. But
this way need to rewrite the common code such as "double
GetCoordinate(int)". Is there any easy way to implement them? What I
mean is that just specializing those constructors rather than
specialize the total class.
Thanks for your help!
Shuisheng