syntax problem for partial template specialization for a template class.

T

toton

Hi,
I am doing some template specialization for a template class, where
specialization is done on a member function. I am not able to get exact
syntax for it.
The code is give as below,
enum DirectionType{
dtX,dtY,dtXD,dtYD
};
template<typename T>
class Point{
T x_;
T y_;
T xd_;
T yd_;
T p_;
T t_;
public:
Point(T x,T y,T p=0,T t=0): x_(x),y_(y),p_(p),t_(t){
xd_= 5;
yd_ =10;
}
template<DirectionType dt>
T x()const;
template<DirectionType dt>
T y()const;
};
template<typename T>
template<>
T Point<T>::x<dtX>()const{
return x_;
}
template<typename T>
template<>
T Point<T>::x<dtY>()const{
return -y_;
}
template<typename T>
template<>
T Point<T>::x<dtXD>()const{
return xd_;
}
template<typename T>
template<>
T Point<T>::x<dtYD>()const{
return -yd_;
}
int main(int argc,char** argv) {
Point<int> p(2,4);
std::cout<<p.x<dtX>()<<std::endl;
return 0;
}

Here , the Point class is parameterized over a type which point holds.
and its member functions x() and y() are parameterized over a
directions type, which to be implemented for 4 directions. I am not
passing this enum in x() & y() member as there are only 4 directions
and results are known, thus I think no if else/ switch is needed inside
x() & y(), instead I can do it with template specialization.
But there is problem with the syntax.

Thanks
abir
 
T

tolgaceylanus

I think the standard forbids such specializations where the enclosing
(class) template
is not specialized.

Tolga Ceylan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top