Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

construction error when template class derives from template class (gcc 4.1.1)

0 views
Skip to first unread message

seaswar

unread,
Aug 30, 2006, 8:13:18 AM8/30/06
to
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! ]

Radu

unread,
Aug 30, 2006, 10:51:32 AM8/30/06
to

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
> };
>
> $ 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

marius lazer

unread,
Aug 30, 2006, 3:52:48 PM8/30/06
to

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

seaswar

unread,
Aug 31, 2006, 11:01:50 AM8/31/06
to
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

0 new messages