 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
frantz Guest
|
Posted: Thu Dec 23, 2004 9:43 pm Post subject: template of template under gcc3.4 and MSVC7.1... |
|
|
I have problem compiling the following code with MSVC7.1.
The .net compiler says that a template parameter is missing for
std::vector (or std::set) in the main function. Which is false since
the second template parameter is templated as well.
However, this works fine under gcc3.4.
It seems that template of template is not well supported under
Window$.
Am I correct?
Here is the code:
--------------->8---------------------------------------
template <class ITEM, template
class A {
public:
typedef CONTAINER<ITEM> Items ;
typedef CONTAINER<std::string> Names ;
Items items ;
Names names ;
} ;
int main() {
typedef A<int, std::vector> AVector ;
typedef A<int, std::set> ASet ;
AVector avector ;
ASet aset ;
}
--------------->8---------------------------------------
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
L.Suresh Guest
|
Posted: Fri Dec 24, 2004 9:48 am Post subject: Re: template of template under gcc3.4 and MSVC7.1... |
|
|
The problem is because the second template parameter you passed while
instantiating template class A, std::vector has two parameters (the
second parameter is allocator and it defaults to std::allocator)
So you template declaration should look like this.
template <typename ITEM,
template class
CONTAINER
....
};
--lsu
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Jonathan Turkanis Guest
|
Posted: Fri Dec 24, 2004 10:03 am Post subject: Re: template of template under gcc3.4 and MSVC7.1... |
|
|
frantz wrote:
| Quote: | I have problem compiling the following code with MSVC7.1.
The .net compiler says that a template parameter is missing for
std::vector (or std::set) in the main function. Which is false since
the second template parameter is templated as well.
However, this works fine under gcc3.4.
It seems that template of template is not well supported under
Window$.
Am I correct?
|
No. The problem is that std::basic_string and std::vector each have more than
one template parameter, and therefore are not suitable arguments for the
template parameter CONTAINER, despite the fact that the template parameters
other than the first have default values.
See http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_closed.html#150
GCC implements a language extension allowing templates with default parameters
to match in these cases.
| Quote: |
Here is the code:
--------------->8---------------------------------------
template <class ITEM, template
class A {
public:
typedef CONTAINER<ITEM> Items ;
typedef CONTAINER<std::string> Names ;
Items items ;
Names names ;
} ;
int main() {
typedef A<int, std::vector> AVector ;
typedef A<int, std::set> ASet ;
AVector avector ;
ASet aset ;
}
|
Jonathan
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|