Unresolved Externals problem
Here's the errors:
Error 3 error LNK2019: unresolved external symbol "public: class Core * __thiscall Handle<class Core>::operator->(void)const " (??C?$Handle@VCore@@@@QBEPAVCore@@XZ) referenced in function _main C:\Users\DJ\documents\visual studio 2010\Projects\14.1 - A Generic Handle Class\14.1 - A Generic Handle Class\main.obj
Error 4 error LNK2019: unresolved external symbol "public: class Handle<class Core> & __thiscall Handle<class Core>::operator=(class Handle<class Core> const &)" (??4?$Handle@VCore@@@@QAEAAV0@ABV0@@Z) referenced in function _main C:\Users\DJ\documents\visual studio 2010\Projects\14.1 - A Generic Handle Class\14.1 - A Generic Handle Class\main.obj
Error 5 error LNK2001: unresolved external symbol "public: class Handle<class Core> & __thiscall Handle<class Core>::operator=(class Handle<class Core> const &)" (??4?$Handle@VCore@@@@QAEAAV0@ABV0@@Z) C:\Users\DJ\documents\visual studio 2010\Projects\14.1 - A Generic Handle Class\14.1 - A Generic Handle Class\Student_info.obj
Error 6 error LNK1120: 2 unresolved externals C:\Users\DJ\documents\visual studio 2010\Projects\14.1 - A Generic Handle Class\Debug\14.1 - A Generic Handle Class.exe 1
Handle.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
#ifndef GUARD_Handle_h
#define GUARD_Handle_h
#include "Grad.h"
template<class T> class Handle
{
public:
Handle(): p(0) { }
Handle(const Handle& s): p(0) { if (s.p) p = s.p->clone(); }
Handle(T* t): p(t) { }
Handle& operator=(const Handle&);
~Handle() { delete p; }
operator bool() const { return p; }
T& operator*() const;
T* operator->() const;
private:
T* p;
};
static bool compare_Core_handles(const Handle<Core>& s1, const Handle<Core>& s2)
{
return s1->name() < s2->name();
}
#endif
|
Handle.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
#include "Handle.h"
#include <stdexcept>
using std::runtime_error;
template <class T> Handle<T>& Handle<T>::operator=(const Handle& rhs)
{
if (&rhs != this) {
delete p;
p = rhs.p ? rhs.p->clone() : 0;
}
return *this;
}
template <class T> T& Handle<T>::operator*() const
{
if (p) return *p;
throw runtime_error("unbound Handle");
}
template <class T> T* Handle<T>::operator->() const
{
if (p) return p;
throw runtime_error("unbound Handle");
}
|
I fixed it by putting all of the functions of Handle.cpp after the class definition in Handle.h
Does anyone know how to make it work by using Handle.cpp?
Topic archived. No new replies allowed.