| View previous topic :: View next topic |
| Author |
Message |
seaswar Guest
|
Posted: Wed Aug 30, 2006 5:13 pm Post subject: construction error when template class derives from template |
|
|
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
|
Posted: Wed Aug 30, 2006 7:51 pm Post subject: Re: construction error when template class derives from temp |
|
|
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
[ 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
|
Posted: Thu Aug 31, 2006 12:52 am Post subject: Re: construction error when template class derives from tem |
|
|
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
|
Posted: Thu Aug 31, 2006 8:01 pm Post subject: Re: construction error when template class derives from temp |
|
|
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 |
|
 |
|