473,325 Members | 2,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

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 1725
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Scott J. McCaughrin | last post by:
The following program compiles fine but elicits this message from the linker: "undefined reference to VarArray::funct" and thus fails. It seems to behave as if the static data-member:...
3
by: YAN KANG / SU | last post by:
Hi, All I am migrating to Studio .NET 2003 from Studio 6.0 and Studio .NET 2002. When I compiled my code, which is compilable both in VC++ 6.0 and Studio .NET 2002, I have an error LNK2019 as the...
3
by: Trapulo | last post by:
I've a datarepeater that loads custom external templates with loadtemplate and bind data to them. All ok. Now I need to localize some text labels, but I don't know how can I change this data. If I...
10
by: Chris Thomasson | last post by:
I am working on a high-speed futures implementation in C++, and was tinkering around with ways to wrap the function pointer logic. I am a C/Assembly programmer that doesn't make a lot of use of...
3
by: s.z.s | last post by:
Hi! I hope the solution to that is not too stupid... I've got three files: <snip test_main.cc> #include"test.hh" int main(void) { A<inta1; a1.saywhat();
1
by: yamitmehta | last post by:
When I compile to code using g++arm of VxWorks 5.5 and put it on my board i get the follwing undefined symbols:- Cpool and Csingleton are template classes. CPool has the static member...
8
by: wdh3rd | last post by:
I'm still new at C and can't solve this problem. I've looked through the FAQ and on the Web, but am not having luck. I'm getting an "undefined reference" error as well as a "Id returned 1 exit...
7
by: JustBeSimple | last post by:
Hi Everyone, I'm having a problem compiling useing the VS2005 .NET I need help to resolve those error, I try to create a new project it doesn't help any suggestion? I got the following errors:...
2
by: saritha2008 | last post by:
Hi, As part of transforming one form of xml to another form, i need to do the below mentioned transformation: My Input XML: <rss> <channel> <item> <assignee...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.