R
.rhavin grobert
Hi group....;-)
i have the following class....
_____________________________________________________
// QSharedReg.hpp
typedef unsigned __int64 QUAD;
using namespace boost;
template<class T> struct _SQSRI {
QUAD qID;
shared_ptr<T> pItem;
};
template <class T> class CQSharedReg {
public:
CQSharedReg();
virtual ~CQSharedReg();
inline UINT Count() const {return m_vector.size();};
shared_ptr<T> const Get(QUAD qID) const;
shared_ptr<T> const GetByIdx(UINT nIdx) const;
shared_ptr<T> Register(QUAD qID);
bool Unregister(QUAD qID);
private:
std::vector<_SQSRI<T> > m_vector;
};
________________________________________________________
....and the following implementation.....
________________________________________________________
// QSharedReg.cpp
//-----------------------------------------------------------------------------
template <class T> CQSharedReg<T>::CQSharedReg() {}
//-----------------------------------------------------------------------------
template <class T> CQSharedReg<T>::~CQSharedReg() {}
//-----------------------------------------------------------------------------
template <class T> shared_ptr<T> const CQSharedReg<T>::Get(QUAD qID)
const {
register UINT nCnt = Count();
_SQSRI<T> const* psqri;
while (nCnt-->0) {
psqri = &m_vector[nCnt];
if (psqri == NULL)
continue;
if (psqri->qID != qID)
continue;
return psqri->pItem;
}
shared_ptr<T> none;
return none;
}
//-----------------------------------------------------------------------------
template <class T> shared_ptr<T> const CQSharedReg<T>::GetByIdx(UINT
nIdx) const {
if (nIdx >= m_vector.size()) {
shared_ptr<T> none;
return none;
}
return m_vector[nIdx].pItem;
}
//-----------------------------------------------------------------------------
template <class T> shared_ptr<T> CQSharedReg<T>::Register(QUAD qID) {
shared_ptr<T> pItem = (shared_ptr<T>) Get(qID);
if (pItem.get() != NULL)
return pItem;
_SQSRI<T> sqri;
sqri.pItem = new T;
sqri.qID = qID;
m_vector.push_back(sqri);
return sqri.pItem;
}
//-----------------------------------------------------------------------------
template <class T> bool CQSharedReg<T>::Unregister(QUAD qID) {
register UINT nCnt = Count();
_SQSRI<T>* psqri;
while (nCnt-->0) {
psqri = &m_vector[nCnt];
if (psqri == NULL)
continue;
if (psqri->qID != qID)
continue;
m_vector.erase(psqri);
return true;
}
return false;
}
________________________________________________________
the object "QSharedReg.obj" compiles fine (is there anything to
compile!?) but when i instatiate it in another class (here in class
CQElement using) ....
________________________________________________________
// from QElement.hpp
CQSharedReg<CQDetail> m_rDetails;
// from QElement.cpp
UINT nCnt = m_rDetails.Count();
shared_ptr<CQDetail> pDetail3 = m_rDetails.Register(3);
nCnt = m_rDetails.Count();
shared_ptr<CQDetail> pDetail5 = m_rDetails.Register(5);
nCnt = m_rDetails.Count();
if (pDetail5.get() != NULL) {
shared_ptr<CQDetail> pDetail1 = m_rDetails.Register(1);
nCnt = m_rDetails.Count();
}
nCnt = m_rDetails.Count();
________________________________________________________
....., i get the following error (name-mangling skipped): ...
QElement.obj : error LNK2001: unresolved external symbol "public:
virtual __thiscall CQSharedReg<class CQDetail>::~CQSharedReg<class
CQDetail>(void)"
QElement.obj : error LNK2001: unresolved external symbol "public:
class boost::shared_ptr<class CQDetail> __thiscall CQSharedReg<class
CQDetail>::Register(unsigned __int64)"
QElement.obj : error LNK2001: unresolved external symbol "public:
__thiscall CQSharedReg<class CQDetail>::CQSharedReg<class
CQDetail>(void)"
....so if i interpret it right, the linker tries for example to find a
function
CQSharedReg<class CQDetail>::~CQSharedReg<class CQDetail>(void)
but that function IS defined...
Any help apreciated, TIA, -.rhavin
i have the following class....
_____________________________________________________
// QSharedReg.hpp
typedef unsigned __int64 QUAD;
using namespace boost;
template<class T> struct _SQSRI {
QUAD qID;
shared_ptr<T> pItem;
};
template <class T> class CQSharedReg {
public:
CQSharedReg();
virtual ~CQSharedReg();
inline UINT Count() const {return m_vector.size();};
shared_ptr<T> const Get(QUAD qID) const;
shared_ptr<T> const GetByIdx(UINT nIdx) const;
shared_ptr<T> Register(QUAD qID);
bool Unregister(QUAD qID);
private:
std::vector<_SQSRI<T> > m_vector;
};
________________________________________________________
....and the following implementation.....
________________________________________________________
// QSharedReg.cpp
//-----------------------------------------------------------------------------
template <class T> CQSharedReg<T>::CQSharedReg() {}
//-----------------------------------------------------------------------------
template <class T> CQSharedReg<T>::~CQSharedReg() {}
//-----------------------------------------------------------------------------
template <class T> shared_ptr<T> const CQSharedReg<T>::Get(QUAD qID)
const {
register UINT nCnt = Count();
_SQSRI<T> const* psqri;
while (nCnt-->0) {
psqri = &m_vector[nCnt];
if (psqri == NULL)
continue;
if (psqri->qID != qID)
continue;
return psqri->pItem;
}
shared_ptr<T> none;
return none;
}
//-----------------------------------------------------------------------------
template <class T> shared_ptr<T> const CQSharedReg<T>::GetByIdx(UINT
nIdx) const {
if (nIdx >= m_vector.size()) {
shared_ptr<T> none;
return none;
}
return m_vector[nIdx].pItem;
}
//-----------------------------------------------------------------------------
template <class T> shared_ptr<T> CQSharedReg<T>::Register(QUAD qID) {
shared_ptr<T> pItem = (shared_ptr<T>) Get(qID);
if (pItem.get() != NULL)
return pItem;
_SQSRI<T> sqri;
sqri.pItem = new T;
sqri.qID = qID;
m_vector.push_back(sqri);
return sqri.pItem;
}
//-----------------------------------------------------------------------------
template <class T> bool CQSharedReg<T>::Unregister(QUAD qID) {
register UINT nCnt = Count();
_SQSRI<T>* psqri;
while (nCnt-->0) {
psqri = &m_vector[nCnt];
if (psqri == NULL)
continue;
if (psqri->qID != qID)
continue;
m_vector.erase(psqri);
return true;
}
return false;
}
________________________________________________________
the object "QSharedReg.obj" compiles fine (is there anything to
compile!?) but when i instatiate it in another class (here in class
CQElement using) ....
________________________________________________________
// from QElement.hpp
CQSharedReg<CQDetail> m_rDetails;
// from QElement.cpp
UINT nCnt = m_rDetails.Count();
shared_ptr<CQDetail> pDetail3 = m_rDetails.Register(3);
nCnt = m_rDetails.Count();
shared_ptr<CQDetail> pDetail5 = m_rDetails.Register(5);
nCnt = m_rDetails.Count();
if (pDetail5.get() != NULL) {
shared_ptr<CQDetail> pDetail1 = m_rDetails.Register(1);
nCnt = m_rDetails.Count();
}
nCnt = m_rDetails.Count();
________________________________________________________
....., i get the following error (name-mangling skipped): ...
QElement.obj : error LNK2001: unresolved external symbol "public:
virtual __thiscall CQSharedReg<class CQDetail>::~CQSharedReg<class
CQDetail>(void)"
QElement.obj : error LNK2001: unresolved external symbol "public:
class boost::shared_ptr<class CQDetail> __thiscall CQSharedReg<class
CQDetail>::Register(unsigned __int64)"
QElement.obj : error LNK2001: unresolved external symbol "public:
__thiscall CQSharedReg<class CQDetail>::CQSharedReg<class
CQDetail>(void)"
....so if i interpret it right, the linker tries for example to find a
function
CQSharedReg<class CQDetail>::~CQSharedReg<class CQDetail>(void)
but that function IS defined...
Any help apreciated, TIA, -.rhavin