Solved

Partial template specialization issues

Posted on 2009-07-11
11
217 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
 
LVL 3

Author Comment

by:Unimatrix_001
ID: 24831730
Ack - accepted too early... jrk mind opening this question please?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

708 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now