473,395 Members | 1,484 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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! ]
Jul 22 '05 #1
2 4745
"Michael Stembera" <m_********@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
Jul 22 '05 #2
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! ]
Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

46
by: J.R. | last post by:
Hi folks, The python can only support passing value in function call (right?), I'm wondering how to effectively pass a large parameter, such as a large list or dictionary? It could achieved...
11
by: BRG | last post by:
I know that default template arguments cannot be used in function templates but are default function parameters legal? That is, is this: ---------------------------------- #include <functional>...
8
by: Robert W. | last post by:
I've almost completed building a Model-View-Controller but have run into a snag. When an event is fired on a form control I want to automatically updated the "connnected" property in the Model. ...
2
by: pagekb | last post by:
Hello, I'm having some difficulty compiling template classes as containers for other template objects. Specifically, I have a hierarchy of template classes that contain each other. Template...
12
by: aaragon | last post by:
Hello all. I have a simple question that seems trivial but I can't make it to work. I have a class that takes as a template argument, another class. The idea is as follows: #include...
74
by: Zytan | last post by:
I have a struct constructor to initialize all of my private (or public readonly) fields. There still exists the default constructor that sets them all to zero. Is there a way to remove the...
6
by: Mark | last post by:
I have a problem with a template class defined: // start matrix.h file template <class Tclass Matrix { public: Matrix() { // default constructor } Matrix(const Subscript rows, const...
3
by: CrazyAtlantaGuy | last post by:
I am working on creating an XSLT that transforms Html into an XML format that can be imported into Framemaker. The challenge, it turns out, is correctly transforming the flat html header tags...
8
by: William Xu | last post by:
Compiling: template <class T = int> T foo(const T& t) {} int main(int argc, char *argv) {} gcc complains:
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.