Skip to main content
gamedev.net
🔒 Locked

Template classes

Started by Lazy303 Dec 19, 2002 at 1:57 PM 11 replies 250+ views
Original Post
Lazy303
Lazy303
Hi! I've written a template class for linked lists. But Now I want to create a new template class that uses the linked list class, but it doesn't work These are my tree classes :
  
template<class E> class CFreeList
template<class E> class CFreeListChunk
template<class T> class CLinkedList

In the CFreeList class I have a member :

CLinkedList<CFreeListChunk<E>>	m_oChunkList;

  
But i get this error cfreelist.h(55) : error C2146: syntax error : missing ',' before identifier 'm_oChunkList' Hmm.. havn't got a clue... plz help! /lazy [edited by - lazy303 on December 19, 2002 3:27:18 PM]
ga
ga
you should probably pass some argument(s) to the template like

CLinkedList m_oChunkList;
Visit our homepage: www.rarebyte.de.stGA
ga
ga
shit...

if it''s like this

  
CLinkedList<T> m_oChunkList;


your CLinkedList - template may need more than one argument ...
Visit our homepage: www.rarebyte.de.stGA
ga
ga
Lazy303, please do what Miserable says


  
CLinkedList<CFreeListChunk<E>> m_oChunkList;


how did you declare CFreeListChunk and CLinkedList???
Visit our homepage: www.rarebyte.de.stGA
Miserable
Miserable
quote:
Original post by Lazy303
The forum removes some of my text!


I repeat: Put your code in source boxes. You do so by using the forum tags (in square brackets) [ source ] and [ /source ] (though without the spaces in the tags, which I insert only to prevent them from turning up as a source box instead of text).

I also suggest you glance at the forum FAQ''s ...
Lazy303
Lazy303
umm.. How do I use those edit boxes?


  

template<class E> class CFreeList
{
stuff

CLinkedList<CFreeListChunk<E>> m_oChunkList;
}

template<class E> class CFreeListChunk
{
stuff
}

template<class T> class CLinkedList
{
stuff
}


[edited by - lazy303 on December 19, 2002 3:26:05 PM]
BitMaster
BitMaster
I think some C++ compilers have problems with using a double ">" for templates. Try to insert a space between them, otherwise they might be confused with the shift operator.
ga
ga
yep... you''re right ... vc++ can''t handle that... (and I think Lazy303 uses vc++ because of the error message...)


quote:
Original post by BitMaster
I think some C++ compilers have problems with using a double ">" for templates. Try to insert a space between them, otherwise they might be confused with the shift operator.



Visit our homepage: www.rarebyte.de.stGA
Lazy303
Lazy303
Thanks!

It was the >> error...

Damn, now when I think about it... I''ve had this problem
before... I never learn...
Oluseyi
Oluseyi
quote:
Original post by Miserable
I repeat: Put your code in source boxes. You do so by using the forum tags (in square brackets) [ source ] and [ /source ] (though without the spaces in the tags, which I insert only to prevent them from turning up as a source box instead of text).

I also suggest you glance at the forum FAQ's ...

It's actually a little more involved than that.

[source] tags place syntax highlighted text in a white box and do not attempt to interpret angular brackets-enclosed as HTML. Like [code] tags, they also display text in monospace font. Unfortunately, the [source] box is rather large for less than say 10 lines of code. To correctly show angular brackets in regular text (including [code] tags-enclosed text), use the HTML entity < and for the opening bracket. Here's a couple of examples:

template < typename T >
ATemplateClassInPlainText
{
...
};

The advantage of the [code] tag is that it maintains whitespace (indenting, etc), which the [source] tag does as well.

How did I write [source] and [code] without the spaces and without the board interpreting them as tags? I used the HTML entity for a left square bracket - ] And how did I get this spiffy small grey text? I used the GDNet editedby style: <span class="editedby"> text here </span>

[Edit: Darnit! Used the wrong entity.]

[edited by - Oluseyi on December 19, 2002 5:27:18 PM]
LilBudyWizer
LilBudyWizer
">>" being interpretted as shift is not an error in the compiler. That is the standard.
Keys to success: Ability, ambition and opportunity.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.