Template class won't build properly
Header
class linkNode {
public:
linkNode(void *p) {
before = 0;
after = 0;
me = p;
}
linkNode *before;
void *me;
linkNode *after;
};
template <class T>
class list
{
public:
list(void) { first = last = NULL; size = 0; }
~list(void) { while(first) deleteNode(first); }
private:
void deleteNode(linkNode *l);
linkNode *first, *last;
unsigned int size;
};
.Cpp
template <class T>
inline void list<T>::deleteNode(linkNode *l) {
if(c->before)
if(c->after) {
c->before->after = c->after;
c->after->be开发者_如何学JAVAfore = c->before;
} else
c->before->after = last = NULL;
else
if(c->after)
c->after = first = NULL;
delete c; size--;
}
I have this set to build as a .lib and it builds fine. When I try ePhys::list<int> myList;
I get a linker error saying it cant find ePhys::list<int>::deleteNode(class ePhys::linkNode *)
This is not a problem with setting up using the library, i have tested with other dummy classes.
I am using MSVC 2010 beta.
Is there any way to get this to link properly?
C++ does not really support the separate compilation of templates - you need to put all your template code in the header file(s).
精彩评论