?
Solved

Partial template specialization issues

Posted on 2009-07-11
11
Medium Priority
?
260 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 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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 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 goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
Suggested Courses

770 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