470,641 Members | 1,578 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,641 developers. It's quick & easy.

undefined external template fn?

Hi group....;-)

i have the following class....
__________________________________________________ ___
// QSharedReg.hpp

typedef unsigned __int64 QUAD;
using namespace boost;

template<class Tstruct _SQSRI {
QUAD qID;
shared_ptr<T pItem;
};
template <class Tclass CQSharedReg {
public:
CQSharedReg();
virtual ~CQSharedReg();
inline UINT Count() const {return m_vector.size();};
shared_ptr<Tconst Get(QUAD qID) const;
shared_ptr<Tconst 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 TCQSharedReg<T>::CQSharedReg() {}

//-----------------------------------------------------------------------------
template <class TCQSharedReg<T>::~CQSharedReg() {}

//-----------------------------------------------------------------------------
template <class Tshared_ptr<Tconst CQSharedReg<T>::Get(QUAD qID)
const {
register UINT nCnt = Count();
_SQSRI<Tconst* psqri;
while (nCnt-->0) {
psqri = &m_vector[nCnt];
if (psqri == NULL)
continue;
if (psqri->qID != qID)
continue;
return psqri->pItem;
}
shared_ptr<Tnone;
return none;
}

//-----------------------------------------------------------------------------
template <class Tshared_ptr<Tconst CQSharedReg<T>::GetByIdx(UINT
nIdx) const {
if (nIdx >= m_vector.size()) {
shared_ptr<Tnone;
return none;
}
return m_vector[nIdx].pItem;
}

//-----------------------------------------------------------------------------
template <class Tshared_ptr<TCQSharedReg<T>::Register(QUAD qID) {
shared_ptr<TpItem = (shared_ptr<T>) Get(qID);
if (pItem.get() != NULL)
return pItem;
_SQSRI<Tsqri;
sqri.pItem = new T;
sqri.qID = qID;
m_vector.push_back(sqri);
return sqri.pItem;
}

//-----------------------------------------------------------------------------
template <class Tbool 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<CQDetailm_rDetails;

// from QElement.cpp

UINT nCnt = m_rDetails.Count();
shared_ptr<CQDetailpDetail3 = m_rDetails.Register(3);
nCnt = m_rDetails.Count();
shared_ptr<CQDetailpDetail5 = m_rDetails.Register(5);
nCnt = m_rDetails.Count();
if (pDetail5.get() != NULL) {
shared_ptr<CQDetailpDetail1 = 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;)
Jun 27 '08 #1
5 1575
On Jun 11, 8:26*am, ".rhavin grobert" <cl...@yahoo.dewrote:
Hi group....;-)

i have the following class....
__________________________________________________ ___
// QSharedReg.hpp

typedef unsigned __int64 QUAD;
using namespace boost;

template<class Tstruct _SQSRI {
* * * * QUAD * * * * * qID;
* * * * shared_ptr<T*pItem;

};

template <class Tclass CQSharedReg {
public:
* * * * CQSharedReg();
* * * * virtual ~CQSharedReg();
* * * * inline UINT * * * * Count() const {return m_vector..size();};
* * * * shared_ptr<Tconst Get(QUAD qID) const;
* * * * shared_ptr<Tconst 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 TCQSharedReg<T>::CQSharedReg() {}

//-------------------------------------------------------------------------*----
template <class TCQSharedReg<T>::~CQSharedReg() {}

//-------------------------------------------------------------------------*----
template <class Tshared_ptr<Tconst CQSharedReg<T>::Get(QUAD qID)
const {
* * * * register UINT nCnt = Count();
* * * * _SQSRI<Tconst* psqri;
* * * * while (nCnt-->0) {
* * * * * * * * psqri = &m_vector[nCnt];
* * * * * * * * if (psqri == NULL)
* * * * * * * * * * * * continue;
* * * * * * * * if (psqri->qID != qID)
* * * * * * * * * * * * continue;
* * * * * * * * return psqri->pItem;
* * * * }
* * * * shared_ptr<Tnone;
* * * * return none;

}

//-------------------------------------------------------------------------*----
template <class Tshared_ptr<Tconst CQSharedReg<T>::GetByIdx(UINT
nIdx) const {
* * * * if (nIdx >= m_vector.size()) {
* * * * * * * * shared_ptr<Tnone;
* * * * * * * * return none;
* * * * }
* * * * return m_vector[nIdx].pItem;

}

//-------------------------------------------------------------------------*----
template <class Tshared_ptr<TCQSharedReg<T>::Register(QUAD qID) {
* * * * shared_ptr<TpItem = (shared_ptr<T>) Get(qID);
* * * * if (pItem.get() != NULL)
* * * * * * * * return pItem;
* * * * _SQSRI<Tsqri;
* * * * sqri.pItem = new T;
* * * * sqri.qID * = qID;
* * * * m_vector.push_back(sqri);
* * * * return sqri.pItem;

}

//-------------------------------------------------------------------------*----
template <class Tbool 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<CQDetailm_rDetails;

// from QElement.cpp

* * * * UINT nCnt = m_rDetails.Count();
* * * * shared_ptr<CQDetailpDetail3 = m_rDetails.Register(3);
* * * * nCnt = m_rDetails.Count();
* * * * shared_ptr<CQDetailpDetail5 = m_rDetails.Register(5);
* * * * nCnt = m_rDetails.Count();
* * * * if (pDetail5.get() != NULL) {
* * * * * * * * shared_ptr<CQDetailpDetail1 = 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;)
Are the namespaces same for both of them ?
Jun 27 '08 #2
On 11 Jun., 15:06, suresh shenoy <msureshshe...@gmail.comwrote:
On Jun 11, 8:26 am, ".rhavin grobert" <cl...@yahoo.dewrote:
Hi group....;-)
i have the following class....
__________________________________________________ ___
// QSharedReg.hpp
typedef unsigned __int64 QUAD;
using namespace boost;
template<class Tstruct _SQSRI {
QUAD qID;
shared_ptr<T pItem;
};
template <class Tclass CQSharedReg {
public:
CQSharedReg();
virtual ~CQSharedReg();
inline UINT Count() const {return m_vector.size();};
shared_ptr<Tconst Get(QUAD qID) const;
shared_ptr<Tconst 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 TCQSharedReg<T>::CQSharedReg() {}
//-------------------------------------------------------------------------*----
template <class TCQSharedReg<T>::~CQSharedReg() {}
//-------------------------------------------------------------------------*----
template <class Tshared_ptr<Tconst CQSharedReg<T>::Get(QUAD qID)
const {
register UINT nCnt = Count();
_SQSRI<Tconst* psqri;
while (nCnt-->0) {
psqri = &m_vector[nCnt];
if (psqri == NULL)
continue;
if (psqri->qID != qID)
continue;
return psqri->pItem;
}
shared_ptr<Tnone;
return none;
}
//-------------------------------------------------------------------------*----
template <class Tshared_ptr<Tconst CQSharedReg<T>::GetByIdx(UINT
nIdx) const {
if (nIdx >= m_vector.size()) {
shared_ptr<Tnone;
return none;
}
return m_vector[nIdx].pItem;
}
//-------------------------------------------------------------------------*----
template <class Tshared_ptr<TCQSharedReg<T>::Register(QUAD qID) {
shared_ptr<TpItem = (shared_ptr<T>) Get(qID);
if (pItem.get() != NULL)
return pItem;
_SQSRI<Tsqri;
sqri.pItem = new T;
sqri.qID = qID;
m_vector.push_back(sqri);
return sqri.pItem;
}
//-------------------------------------------------------------------------*----
template <class Tbool 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<CQDetailm_rDetails;
// from QElement.cpp
UINT nCnt = m_rDetails.Count();
shared_ptr<CQDetailpDetail3 = m_rDetails.Register(3);
nCnt = m_rDetails.Count();
shared_ptr<CQDetailpDetail5 = m_rDetails.Register(5);
nCnt = m_rDetails.Count();
if (pDetail5.get() != NULL) {
shared_ptr<CQDetailpDetail1 = 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;)

Are the namespaces same for both of them ?
yes...
Jun 27 '08 #3
..rhavin grobert wrote:
Hi group....;-)

i have the following class....
__________________________________________________ ___
// QSharedReg.hpp

typedef unsigned __int64 QUAD;
using namespace boost;

template<class Tstruct _SQSRI {
QUAD qID;
shared_ptr<T pItem;
};
template <class Tclass CQSharedReg {
public:
CQSharedReg();
virtual ~CQSharedReg();
inline UINT Count() const {return m_vector.size();};
shared_ptr<Tconst Get(QUAD qID) const;
shared_ptr<Tconst 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
[snip]
>
...., 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;)
The short answer is: put the template definition into the header. For a
longer account, see the FAQ:

http://www.parashift.com/c++-faq-lit...html#faq-35.13

Best

Kai-Uwe Bux
Jun 27 '08 #4
On Jun 11, 7:26 am, ".rhavin grobert" <cl...@yahoo.dewrote:
Hi group....;-)

i have the following class....
__________________________________________________ ___
// QSharedReg.hpp

typedef unsigned __int64 QUAD;
using namespace boost;

template<class Tstruct _SQSRI {
QUAD qID;
shared_ptr<T pItem;

};

template <class Tclass CQSharedReg {
public:
CQSharedReg();
virtual ~CQSharedReg();
inline UINT Count() const {return m_vector.size();};
shared_ptr<Tconst Get(QUAD qID) const;
shared_ptr<Tconst 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 TCQSharedReg<T>::CQSharedReg() {}

//-----------------------------------------------------------------------------
template <class TCQSharedReg<T>::~CQSharedReg() {}

//-----------------------------------------------------------------------------
template <class Tshared_ptr<Tconst CQSharedReg<T>::Get(QUAD qID)
const {
register UINT nCnt = Count();
_SQSRI<Tconst* psqri;
while (nCnt-->0) {
psqri = &m_vector[nCnt];
if (psqri == NULL)
continue;
if (psqri->qID != qID)
continue;
return psqri->pItem;
}
shared_ptr<Tnone;
return none;

}

//-----------------------------------------------------------------------------
template <class Tshared_ptr<Tconst CQSharedReg<T>::GetByIdx(UINT
nIdx) const {
if (nIdx >= m_vector.size()) {
shared_ptr<Tnone;
return none;
}
return m_vector[nIdx].pItem;

}

//-----------------------------------------------------------------------------
template <class Tshared_ptr<TCQSharedReg<T>::Register(QUAD qID) {
shared_ptr<TpItem = (shared_ptr<T>) Get(qID);
if (pItem.get() != NULL)
return pItem;
_SQSRI<Tsqri;
sqri.pItem = new T;
sqri.qID = qID;
m_vector.push_back(sqri);
return sqri.pItem;

}

//-----------------------------------------------------------------------------
template <class Tbool 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<CQDetailm_rDetails;

// from QElement.cpp

UINT nCnt = m_rDetails.Count();
shared_ptr<CQDetailpDetail3 = m_rDetails.Register(3);
nCnt = m_rDetails.Count();
shared_ptr<CQDetailpDetail5 = m_rDetails.Register(5);
nCnt = m_rDetails.Count();
if (pDetail5.get() != NULL) {
shared_ptr<CQDetailpDetail1 = 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;)
AFAIK, you cannot have a template declared in one file and the
implementation on anther one, unless the "export" keyword is used. But
(again AFAIK) there's only one compiler that implements
"export" (can't remember it's name).

Just a thought.
Jun 27 '08 #5
On 12 Jun, 00:22, Fernando Gómez <fernando.a.gome...@gmail.comwrote:
AFAIK, you cannot have a template declared in one file and the
implementation on anther one, unless the "export" keyword is used.
You could, but you would have to include the definitions somehow. It
is pretty standard to write the definitions in a .tpp file (or
similar), and then #include this file in the header file.

Of course, from the compiler's POV it would not be much different from
a single file.
But (again AFAIK) there's only one compiler that implements
"export" (can't remember it's name).

Just a thought.
Comeau has 'export'. I think Intel C++ has it too. (Since they're both
based on EDG's front end)

DP
Jun 27 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Scott J. McCaughrin | last post: by
3 posts views Thread by Trapulo | last post: by
3 posts views Thread by s.z.s | last post: by
8 posts views Thread by wdh3rd | last post: by
1 post views Thread by Korara | last post: by
???
1 post views Thread by Stoney L | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.