Problem with templates<> and classes

Started by
6 comments, last by Zibar 20 years, 10 months ago
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.
Advertisement
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
Does your LinkedList class have a default constructor?
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.
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);
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 );
};
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
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.

This topic is closed to new replies.

Advertisement