-
link time error
I get the following link time errors from mvs, any ideas what i have done wrong?
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/BasicTemplateListTest.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
BasicTemplateListTest.exe - 2 error(s), 0 warning(s)
-
i do have a main() though :rolleyes:
-
hmm i've done that and it compiles, its just when i come to build it shoots the errors at me. maybe some code will help?
Code:
#include "TestTemplateNodes.h"
template <class N>
int main()
{
CTemplateList<N> test;
TestNodes(test);
return 0;
}
is it ok to set main as a template?
-
Maybe the problem is that an instance of the function has not been instantiated. A template is just an outline for code that is suppossed to get filled in or completed as needed depending on how it gets called. As it stands now, the code provided is simply the framework, its likely that no actual code yet exists for the function which is why main can't be found. Might be interesting to see if this would work if you actually made a main function call with a particular type supplied for the CTemplateList object so that the function could be instantiated and thus found by the linker. But... it would be best to not have main as a templated function I'm guessing.
-
hmm its just when i take away the template line, i get like 52 errors, all blabbing on about:
error C2662: 'push_front' : cannot convert 'this' pointer from 'class CTemplateList' to 'class CTemplateList<T> &'
Reason: cannot convert from 'class CTemplateList' to 'class CTemplateList<T>'
Conversion requires a second user-defined-conversion operator or constructor
Unless my understanding of templates is wrong, are these acceptable templates?
Code:
template <class T>
class CTemplateNode
{
public:
CTemplateNode() : m_pPrev(0), m_pNext(0), m_iIndex(0) {}
CTemplateNode<T> value() const {return m_tType;}
void value(const T& n) {m_tType = n;}
int index() const {return m_iIndex;}
CTemplateNode<T> *m_pPrev, *m_pNext, m_tType;
int m_iInt, m_iIndex;
};
Code:
template <class T>
class CTemplateList
{
public:
CTemplateList() : m_pNHead(0), m_pNTail(0), m_pNCurrent(0), m_iLSize(0) {}
~CTemplateList() {if(m_pNHead) clear();}
int size() const {return m_iLSize;}
bool empty();
void clear();
void assign(int n, int e);
void operator=(const CTemplateList<T>& list);
CTemplateNode<T>* front() {return m_pNHead;}
CTemplateNode<T>* back() {return m_pNTail;}
void push_front(const T& e);
void pop_front() {remove(m_pNHead);}
void push_back(const T& e);
void pop_back() {remove(m_pNTail);}
CTemplateNode<T>* inserte(int iter, int e) {return(search(iter));}
CTemplateNode<T>* erase(int iter) {remove(search(iter)); return m_pNCurrent = m_pNCurrent->m_pNext;}
void removee(CTemplateNode<T> e);
void index();
void remove(CTemplateNode<T> *node);
void insert(const T& e, CTemplateNode<T> *node);
void reset() {m_pNCurrent=m_pNHead;}
CTemplateNode<T>* getcurrent() {return m_pNCurrent;}
CTemplateNode<T>* search(const T& e);
CTemplateNode<T>* search_index(const T& e);
CTemplateNode<T>* next();
CTemplateNode<T>* prev();
protected:
CTemplateNode<T> *m_pNHead, *m_pNTail, *m_pNCurrent, m_tType;
int m_iLSize;
};
-
booya! :D silly old me forgot to give the template a type... ty for all your help :)