473,320 Members | 1,857 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 1682
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Paul MG | last post by:
Hi Template partial specialization always seems like a fairly straightforward concept - until I try to do it :). I am trying to implement the input sequence type (from Stroustrup section...
6
by: Patrick Kowalzick | last post by:
Dear all, I have a question about default template parameters. I want to have a second template parameter which as a default parameter, but depends on the first one (see below). Is something...
8
by: Agent Mulder | last post by:
Hi group, I have a problem with partial template specialization. In the code below I have a template struct Music with one method, play(), and three kinds of music, Jazz, Funk and Bach. When I...
1
by: BekTek | last post by:
I'm still confused about the template partial specialization which is used in many libraries.. due to lack of introduction for beginner.. Could you tell me about that in short? Thanks in...
5
by: Levent | last post by:
Hi, Why doesn't this work? (tried with gcc 3.3.3 and VC++ 7.1): #include <iostream> template<class T, unsigned N> struct Foo { void func(); }; template<class T, unsigned N>
1
by: Alfonso Morra | last post by:
if I have a class template declared as ff: (BTW is this a partial specialization? - I think it is) template <typename T1, myenum_1 e1=OK, my_enum_2=NONE> class A { public: A(); virtual...
9
by: Marek Vondrak | last post by:
Hello. I have written the following program and am curious why it prints "1" "2". What are the exact effects of explicitly providing function template parameters at the call? Is the second...
9
by: stephen.diverdi | last post by:
Can anyone lend a hand on getting this particular template specialization working? I've been trying to compile with g++ 4.1 and VS 2005. ...
8
by: flopbucket | last post by:
Hi, I want to provide a specialization of a class for any type T that is a std::map. template<typename T> class Foo { // ... };
1
by: Ioannis Gyftos | last post by:
Hello, First the code :) /////////////////////////////////////////////////////////////////////////////////// // in another header file namespace LJC{
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.