470,810 Members | 861 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,810 developers. It's quick & easy.

Template partial specialization question

Hello group,

Consider such a class hierachy:

template<typename Type>
class SomeConcreteUsefulClass {}

template<typename Type, typename SomeUsefulClass>
class BaseClass {}

template<typename Type>
class BaseClass<Type, SomeConcreteUsefulClass<Type> > {} // line 10

The compiler (g++) complains about syntax error before '>' on line 10.
Is it illegal to use the declared typename in the type specification of
a template class in template args list, or am I just missing something
in my code?

Thanks in advance,
melfar

May 10 '06 #1
7 1580
me****@gmail.com wrote:
Hello group,

Consider such a class hierachy:

template<typename Type>
class SomeConcreteUsefulClass {}

template<typename Type, typename SomeUsefulClass>
class BaseClass {}

template<typename Type>
class BaseClass<Type, SomeConcreteUsefulClass<Type> > {} // line 10

The compiler (g++) complains about syntax error before '>' on line 10.
Is it illegal to use the declared typename in the type specification of
a template class in template args list, or am I just missing something
in my code?


Apart from semi-columns after class definitions (you *did* put
semi-columns, did you?), everything compiles fine here. Do you have a
more complete example?
Jonathan

May 10 '06 #2
Yeah, semi-colons are in place.
In the actual code there's just one more template parameter in the
list.
Interestingly, if I substitute SomeConcreteUsefulClass<Type> with Test
(and adding a forward-declaration of class Test; ), it successfully
goes through.
the definition of SomeConcreteUsefulClass is properly #included.

May 10 '06 #3
Jonathan Mcdougall <jo***************@gmail.com> wrote:
Apart from semi-columns after class definitions (you *did* put
semi-columns, did you?), everything compiles fine here. Do you have a
more complete example?


<nit>
They are semicolons, not semi-columns.
</nit>

--
Marcus Kwok
Replace 'invalid' with 'net' to reply
May 10 '06 #4
Marcus Kwok wrote:
Jonathan Mcdougall <jo***************@gmail.com> wrote:
Apart from semi-columns after class definitions (you *did* put
semi-columns, did you?), everything compiles fine here. Do you have a
more complete example?


<nit>
They are semicolons, not semi-columns.
</nit>


Oh, thanks, good to know :)
Jonathan "French Canadian" Mcdougall

May 10 '06 #5
me****@gmail.com wrote:
Yeah, semi-colons are in place.
In the actual code there's just one more template parameter in the
list.
Interestingly, if I substitute SomeConcreteUsefulClass<Type> with Test
(and adding a forward-declaration of class Test; ), it successfully
goes through.
the definition of SomeConcreteUsefulClass is properly #included.


Well just post a complete, "compilable" example that fails on your
compiler.
Jonathan

May 10 '06 #6
There was a problem by my side.
SomeConcreteUsefulClass contains a cross reference to BaseClass.
So, in fact it was undefined on the moment of declaration of BaseClass.

If I add a forward declaration of SomeConcreteUsefulClass :

template<typename T> class SomeConcreteUsefulClass;

The code compiles okay, but after the inclusion of actual
SomeConcreteUsefulClass definition, the actual code doesn't seem to be
compiled.
I get symbol not found exceptions from the dynamic linker on runtime.

Is it okay to forward declare template classes?

May 10 '06 #7
me****@gmail.com wrote:

Please quote the message you are answering to.
There was a problem by my side.
SomeConcreteUsefulClass contains a cross reference to BaseClass.
So, in fact it was undefined on the moment of declaration of BaseClass.

If I add a forward declaration of SomeConcreteUsefulClass :

template<typename T> class SomeConcreteUsefulClass;

The code compiles okay, but after the inclusion of actual
SomeConcreteUsefulClass definition, the actual code doesn't seem to be
compiled.
I get symbol not found exceptions from the dynamic linker on runtime.
You don't seem to want to post your code. How can we help you?
Is it okay to forward declare template classes?


Yes.
Jonathan

May 10 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

17 posts views Thread by Paul MG | last post: by
6 posts views Thread by Patrick Kowalzick | last post: by
8 posts views Thread by Agent Mulder | last post: by
9 posts views Thread by stephen.diverdi | last post: by
1 post views Thread by Ioannis Gyftos | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.