Solved

Partial template specialization issues

Posted on 2009-07-11
11
239 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 500 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

776 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