partial template specialization

Mar 9, 2009 at 2:16pm
I have a template class which takes two template parameters. I want to make a template specification for only one of the types, but it appears as though I can make a specialization class if I specifiy both types. Is this true?

1
2
3
4
5
6
7
8
9
template <typename a,typename b>
class C {};

template <>
class C<int,int> { };   // works OK

template <>
class C<typename a,int> {}; // I want something like this.. but
                            //  this doesn't work 


Am I just going about this the wrong way?

Thanks in advance.
Mar 9, 2009 at 2:39pm
The correct syntax should be
1
2
template <typename a>
class C<a,int> {};
Mar 9, 2009 at 2:49pm
EDIT: nah that's not working for me either.

1
2
3
4
5
template <typename a,typename b>
class C {};

template <typename a>
class C<a,int> {};


I get errors:

error C2065: 'a' : undeclared identifier
error C2687: cannot define a nested UDT of a template class out of line


could it be a problem with VS? I'm using VS 7.0

EDIT again:

After further research it does appear to be a bug/shortcoming of this version of VS.

Thanks!
Last edited on Mar 9, 2009 at 2:59pm
Mar 9, 2009 at 10:47pm
Did you try

template< typename A >
class C<int> {};

?
Mar 9, 2009 at 11:17pm
yeah -- still get the error C2687: cannot define a nested UDT of a template class out of line

I need to upgrade VS -- if only I didn't have to upgrade my OS to do so.

Ah well, this wasn't so important -- just means I can't make void functors. Not a serious issue.

Thanks.
Last edited on Mar 9, 2009 at 11:18pm
Topic archived. No new replies allowed.