| Topic: |
DEVELOP > c-Plus-Plus |
| User: |
"Michael Stembera" |
| Date: |
19 Nov 2003 05:34:01 PM |
| Object: |
Default Parameters in Nested Templates ? |
I would like to use default parameters in nested templates but MS VC++
7.1 chokes on it. Does anyone know how to fix the simple example
below or if indeed it is possible?
template <int N=7>
class A
{
};
template < template <int N=7> class T >
class B
{
A<> a_default; // A works fine using 7 as the default value
T<5> t_5; // T works fine using 5 explicitly
T<> t_default; // error C2976: 'T' : too few template arguments
// why is the default value 7 not getting used here ?
};
int main(int, char**)
{
B< A > b;
return 0;
}
Thanks in advance!
Michael
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
.
|
|
| User: "Victor Bazarov" |
|
| Title: Re: Default Parameters in Nested Templates ? |
19 Nov 2003 09:11:34 PM |
|
|
"Michael Stembera" <m_stembera@yahoo.com> wrote...
I would like to use default parameters in nested templates but MS VC++
7.1 chokes on it. Does anyone know how to fix the simple example
below or if indeed it is possible?
template <int N=7>
class A
{
};
template < template <int N=7> class T >
Did you actually mean to say
template<class T = A<7> >
???
class B
{
A<> a_default; // A works fine using 7 as the default value
T<5> t_5; // T works fine using 5 explicitly
T<> t_default; // error C2976: 'T' : too few template arguments
// why is the default value 7 not getting used here ?
I don't think the syntax you tried is actually allowed...
};
int main(int, char**)
{
B< A > b;
return 0;
}
Victor
.
|
|
|
|
| User: "Richard Smith" |
|
| Title: Re: Default Parameters in Nested Templates ? |
21 Nov 2003 03:30:41 AM |
|
|
Michael Stembera wrote:
I would like to use default parameters in nested templates but MS VC++
7.1 chokes on it. Does anyone know how to fix the simple example
below or if indeed it is possible?
template <int N=7>
class A {};
template < template <int N=7> class T >
class B
{
A<> a_default; // A works fine using 7 as the default value
T<5> t_5; // T works fine using 5 explicitly
T<> t_default; // error C2976: 'T' : too few template arguments
// why is the default value 7 not getting used here ?
From the Standard itself, it's not clear whether or not his
should work. There is a defect report (#150, part 2) on
this. The "rationale" section of the DR says
| Default arguments are allowed for the parameters of a
| template template parameter, and those default arguments
| alone will be considered in a specialisation of the
| template template parameter within a template defintion;
| any default arguments for the parameters of teh template
| template argument are ignored.
This means that your example should compile, and should use
the default argument, 7. To clarify which 7 this is picking
up, let me slightly modify your example:
template <int N = 7> class A {};
template < template <int N = 5> class T > class B {
A<> a; // uses A<7>
T<> t; // uses A<5>
};
--
Richard Smith
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
.
|
|
|
|

|
Related Articles |
|
|