By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,016 Members | 1,033 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,016 IT Pros & Developers. It's quick & easy.

syntax problem for partial template specialization for a template class.

P: n/a
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{
template<typename T>
class Point{
T x_;
T y_;
T xd_;
T yd_;
T p_;
T t_;
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>
T Point<T>::x<dtX>()const{
return x_;
template<typename T>
T Point<T>::x<dtY>()const{
return -y_;
template<typename T>
T Point<T>::x<dtXD>()const{
return xd_;
template<typename T>
T Point<T>::x<dtYD>()const{
return -yd_;
int main(int argc,char** argv) {
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.


Dec 28 '06 #1
Share this Question
Share on Google+
1 Reply

P: n/a

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

Tolga Ceylan

Dec 28 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.