473,396 Members | 1,860 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

syntax problem for partial template specialization for a template class.

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<intp(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

Dec 28 '06 #1
1 1595

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

Tolga Ceylan

Dec 28 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Agent Mulder | last post by:
Hi group, I have a problem with partial template specialization. In the code below I have a template struct Music with one method, play(), and three kinds of music, Jazz, Funk and Bach. When I...
4
by: TT \(Tom Tempelaere\) | last post by:
Comeau compiler complains (too few arguments for class template "B") at line *** #include <memory> template<typename T, size_t n> struct A {}; template<typename T, size_t n> struct B;
5
by: Levent | last post by:
Hi, Why doesn't this work? (tried with gcc 3.3.3 and VC++ 7.1): #include <iostream> template<class T, unsigned N> struct Foo { void func(); }; template<class T, unsigned N>
4
by: Alfonso Morra | last post by:
Does VC 7.1 support template specialization and partial specialization ?
6
by: wkaras | last post by:
I tried a couple of compilers, and both gave errors compiling this: template <bool fin, typename T> T foo(T val); template <typename T> T foo<true, T>(T val) { return(val); } But both gave...
9
by: Marek Vondrak | last post by:
Hello. I have written the following program and am curious why it prints "1" "2". What are the exact effects of explicitly providing function template parameters at the call? Is the second...
10
by: jason.cipriani | last post by:
I never seem to be able to get this right. Here I have some code: template <typename T, int Nclass A { void f (T); }; template <typename Tvoid A<T,1>::f (T) { } template <typename Tvoid...
1
by: Ioannis Gyftos | last post by:
Hello, First the code :) /////////////////////////////////////////////////////////////////////////////////// // in another header file namespace LJC{
1
by: farseerfc | last post by:
Hi, everyone here loves C++; As a student studying data structure, I'm writting a single list (with only one pointer to identity the next node in its node struct) simulating std::list like: ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.