Archived

This topic is now archived and is closed to further replies.

Problem with templates<> and classes

This topic is 5309 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have this kind of class (first of all - I use VC++.NET) class XMLParser { struct Scene { LinkedList< SceneObject > objectList; } struct SceneObject { } LinkedList< Scene > sceneList; XMLParser ~XMLParser(); // static void StartElementHandler(void * data, const char * element, const char ** attribute); static void EndElementHandler( void *data, const char *el ); } I''m using the expat library for XML parsing. This class should parse an .xml file and create a list of scenes. XMLParser constructor initializes the expat XML parser and the StartElementHandler and EndElementHandler are callbacks that handle the parsing needed by expat. The problem is the templated LinkeList class. I want to "new LinkedList< Scene >()". I can''t do it inside the class decalration and I can''t do it outside of the class declaration. In the first case I get a compiler error (obviously) and in the second one a linker error. If I do: XMLMovieParser::sceneList = new LinkedList< Scene >(); I get C2512 no appropriate default constructor available and C2955 use of class template requires template list If I do inside the constructor: sceneList = new LinkedList< Scene >(); I get an unresolved external symbol errors: LNK2001 and LNK2019 etc.

Share this post


Link to post
Share on other sites
Are you saying you would like a static list?

In the .h:
class poop
{
static std::list<corn_chunks> poop_list;
}

Then in the .cpp:
//with global scope...
static std::list<corn_chunks> poop:oop_list();

good luck
have fun

Share this post


Link to post
Share on other sites
quote:
Original post by Zibar
The problem is the templated LinkeList class. I want to "new LinkedList< Scene >()".

Why do you want to do that? sceneList is an object, new returns a pointer.

Share this post


Link to post
Share on other sites
Where do you define your template class or is it in a compiler library? I bet it is where the problem lies. But I had a similar problem in VC++ 6.0 Pro and I solved it by passing a dummy varible in the parameters...

Ex:

template void funtion (void *value, dummy);

Share this post


Link to post
Share on other sites
emplate< class Object > class LinkedList
{
public:
struct Node
{
Object *object;

Node *next;
// VC++ Note: Visual Studio .NET does not allow the
// definition of member functions of nested classes/structs
// outside the classes (though this might be supported by
// the C++ language)
Node()
{
object = new Object();
}
~Node()
{
delete object;
}
};

private:
Node *currentNode;

public:
Node *headNode;
Node *tailNode;

public:
LinkedList( void );
~LinkedList( void );

// Adds a new node to the list
void AddNewNode( void );
// Gets the next node in the list
Node *GetNextNode( void );
// Sets the head node as the current node
void ResetCurrentNode( void );
};

Share this post


Link to post
Share on other sites
quote:
Original post by SabreMan
quote:
Original post by Zibar
The problem is the templated LinkeList class. I want to "new LinkedList< Scene >()".

Why do you want to do that? sceneList is an object, new returns a pointer.


a typo... sorry! the compiler would catch it anyway

Share this post


Link to post
Share on other sites
quote:
Original post by frogboy134
Where do you define your template class or is it in a compiler library? I bet it is where the problem lies. But I had a similar problem in VC++ 6.0 Pro and I solved it by passing a dummy varible in the parameters...

Ex:

template void funtion (void *value, dummy);


well the problem seems to be much more severe... it probably has to do something with the C xml library expat (not their bug but mine) my C++ wrapper of expat and the templated linked list class.

Share this post


Link to post
Share on other sites