C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

template of template under gcc3.4 and MSVC7.1...

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
frantz
Guest





PostPosted: Thu Dec 23, 2004 9:43 pm    Post subject: template of template under gcc3.4 and MSVC7.1... Reply with 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?

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





PostPosted: Fri Dec 24, 2004 9:48 am    Post subject: Re: template of template under gcc3.4 and MSVC7.1... Reply with quote



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
Quote:

class A {

....
};

--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





PostPosted: Fri Dec 24, 2004 10:03 am    Post subject: Re: template of template under gcc3.4 and MSVC7.1... Reply with quote



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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.