473,244 Members | 1,320 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,244 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 1720
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: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...

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.