How to refer to typedef defined in template class
I'm new to C++ templates and I'm heavily struggling with some compiler
complaints. I'm defining a class-scope type in a template class and want
to refer to this type from somewhere else. I tried different ways to
qualify the type's name but the only thing I achieve is getting different
error messages.
Here's the definition of my class in mylist.h, a classic list implementation:
template<typename T> class MyList {
public:
class ListElement; // forward declaration
typedef ListElement* LPOS; // the problematic typedef
// helper class for list elements
class ListElement {
LPOS next;
int content;
public:
ListElement(T);
LPOS getNext();
...
};
// the list itself
MyList();
ListElement* first;
LPOS add(T);
LPOS insert(T, LPOS);
... // more list functions
};
Now I want to use the LPOS type from outside in main.cpp:
include "mylist.h"
...
void testList (void) {
LPOS pos; // compiler error: expected ';' before pos
MyList<T>::LPOS pos; // compiler error: expected initializer before pos
MyList::LPOS pos; // compiler error: expected ';' before pos
I tried to use "using" but that didn't lead anywhere either. Any help will
be greatly appreciated.
No comments:
Post a Comment