Solved

Partial template specialization issues

Posted on 2009-07-11
11
252 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
typedef std::deque<BYTE> ByteVector is broken in vs2012 23 91
Dynamically allocate memory 9 70
print bytes of an integer 6 29
what type of pointer is this pointer? 3 24
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
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 how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

696 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