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 

construction error when template class derives from template

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





PostPosted: Wed Aug 30, 2006 5:13 pm    Post subject: construction error when template class derives from template Reply with quote



I get the following error under gcc 4.1.1 but works fine under gcc
3.2.3. Is my construction not valid?

file tp.cpp:
template<template<typename> class>
class B { };

template<typename>
class C : public B<C> {
C() : B<C>() { } // line 6
};

$ g++ -c tp.cpp
tp.cpp: In constructor 'C< <template-parameter-1-1> >::C()':
tp.cpp:6: error: type/value mismatch at argument 1 in template
parameter list for 'template<template<class>
class<template-parameter-1-1> > class B'
tp.cpp:6: error: expected a class template, got 'C<
<template-parameter-1-1> >'


Thanks
Suresh


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Radu
Guest





PostPosted: Wed Aug 30, 2006 7:51 pm    Post subject: Re: construction error when template class derives from temp Reply with quote



seaswar wrote:
Quote:
I get the following error under gcc 4.1.1 but works fine under gcc
3.2.3. Is my construction not valid?

file tp.cpp:
template<template<typename> class
class B { };

template<typename
class C : public B<C> {
C() : B<C>() { } // line 6
};

$ g++ -c tp.cpp
tp.cpp: In constructor 'C< <template-parameter-1-1> >::C()':
tp.cpp:6: error: type/value mismatch at argument 1 in template
parameter list for 'template<template<class
class<template-parameter-1-1> > class B'
tp.cpp:6: error: expected a class template, got 'C
template-parameter-1-1> >'

should be:

template<typename>
class C : public B<C> {
C() : B() { } // line 6
};

As a side note VC8 accepts C() : B<C>() w/o complain.

HTH
Radu
Quote:

Thanks
Suresh



[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
marius lazer
Guest





PostPosted: Thu Aug 31, 2006 12:52 am    Post subject: Re: construction error when template class derives from tem Reply with quote



seaswar wrote:
Quote:
I get the following error under gcc 4.1.1 but works fine under gcc
3.2.3. Is my construction not valid?

file tp.cpp:
template<template<typename> class
class B { };

template<typename
class C : public B<C> {
C() : B<C>() { } // line 6
};


The compiler is correct. Did you mean to use one of the following
constructs instead?

template<typename>
class B { };

template<template<typename> class T = B>
class C : public T<C<T> >
{
C() : T<C<T> >() {}
};

template<typename T>
class A : public B<A<T> >
{
A() : B<A<T> >() {}
};


Marius


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
seaswar
Guest





PostPosted: Thu Aug 31, 2006 8:01 pm    Post subject: Re: construction error when template class derives from temp Reply with quote

No. B is a class template that takes a template template parameter. C
is a class template (its template parameter is a typename; not a
template) that derives from B and passes itself as the template
argument to B. The problem occurs in the constructor of C. The compiler
thinks C is a class when it is clearly not. C is a class template (and
is a valid argument, IMO, for B's template parameter).

A work-around for this problem:

template<template<typename> class>
class B { };

template<typename>
class C;

typedef B<C> T;

template<typename>
class C : public T {
C() : T() { } // line 6
};


Sounds like a bug to me.
Suresh

marius lazer wrote:
Quote:
seaswar wrote:
I get the following error under gcc 4.1.1 but works fine under gcc
3.2.3. Is my construction not valid?

file tp.cpp:
template<template<typename> class
class B { };

template<typename
class C : public B<C> {
C() : B<C>() { } // line 6
};


The compiler is correct. Did you mean to use one of the following
constructs instead?

template<typename
class B { };

template<template<typename> class T = B
class C : public T<C<T
{
C() : T<C<T> >() {}
};

template<typename T
class A : public B<A<T
{
A() : B<A<T> >() {}
};


Marius


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