Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Partial template specialization issues

Posted on 2009-07-11
11
Medium Priority
?
263 Views
Last Modified: 2012-05-07
Hello.

Is there anyway for me to accomplish something as follows where the specialised template is only specialised for a number of parameters (in this case 1), rather than them all?

Thanks,
Uni
template<typename TA, typename TB=int>
class CClass{
};
 
template<>
class CClass<typename TA, double>{
};

Open in new window

0
Comment
Question by:Unimatrix_001
  • 6
  • 2
11 Comments
 
LVL 12

Expert Comment

by:Let_Me_Be
ID: 24831715
Yes, but only in the opposite direction (left to right).
template < typename A, typename B >
class SomeClass
{
    A a;
    B b;
};
 
template < typename B >
class SomeClass<int,B>
{
    int a;
    B b;
};

Open in new window

0
 
LVL 3

Author Comment

by:Unimatrix_001
ID: 24831725
Yeugh... this template business just keeps getting uglier every turn! :(
0
 
LVL 86

Accepted Solution

by:
jkr earned 2000 total points
ID: 24831726
Yes, that can be done, only the syntax  is different:
template<typename TA, typename TB=int>
class CClass{
};
 
template<typename TA>
class CClass<TA,double>{
};

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Author Comment

by:Unimatrix_001
ID: 24831730
Ack - accepted too early... jrk mind opening this question please?
0
 
LVL 3

Author Comment

by:Unimatrix_001
ID: 24831763
Yes if you wouldn't mind. Thanks.
0
 
LVL 12

Expert Comment

by:Let_Me_Be
ID: 24831776
Sorry for the confusion :)

For some reason I had really stored in my memory that you have to do partial specialization from left to right (and I can't figure out why).
0
 
LVL 3

Author Comment

by:Unimatrix_001
ID: 24831780
LMB, don't let it worry you. ;) Not a problem at all.

Uni.
0
 
LVL 3

Author Closing Comment

by:Unimatrix_001
ID: 31602459
...and closed again! ;)
0
 
LVL 3

Author Comment

by:Unimatrix_001
ID: 24831829
Cheers.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question