Template partial specialization question

M

melfar

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
 
J

Jonathan Mcdougall

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
 
M

melfar

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

Marcus Kwok

Jonathan Mcdougall said:
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>
 
J

Jonathan Mcdougall

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
 
M

melfar

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

Jonathan Mcdougall

(e-mail address removed) 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top