Linking static library including template

R

Roland Raschke

Hi,
I'm a novice in using templates and want to write a static library
with some communication classes. One of these classes uses two
instances of a ringbuffer template as class members:

template <class T> class CRingBuffer
{
public:
...
bool PutData( const T& value );
...
};

typedef CRingBuffer<unsigned char> tByteFIFO;
class CCommDriver
{
...
tByteFIFO m_RxRing;
...
};

I can compile and link this library without errors, but if want to use
the class CCommDriver in an application the linker returns errors for
any used member function of CRingBuffer, i.e.:
error LNK2001: Unresolved external "public: bool __thiscall
CRingBuffer<unsigned char>::putData(unsigned char const &)"
What's the problem? I think the compiler should create the necessary
template code for unsigned byte because it is used inside the
CCommDriver class...

Thanks for your help!

Regards,
Roland
 
K

Kevin Goodsell

Roland said:
Hi,
I'm a novice in using templates and want to write a static library
with some communication classes.

"Static library" is not something that is defined as part of C++. If
you're having a problem with that, the appropriate place to ask is a
group that discusses your implementation. comp.lang.c++ only discusses
the C++ language itself.
I can compile and link this library without errors, but if want to use
the class CCommDriver in an application the linker returns errors for
any used member function of CRingBuffer, i.e.:
error LNK2001: Unresolved external "public: bool __thiscall
CRingBuffer<unsigned char>::putData(unsigned char const &)"

[34.14] How can I avoid linker errors with my template classes?
http://www.parashift.com/c++-faq-lite/containers-and-templates.html#faq-34.14

While you're at it:

[5.8] How do I post a question about code that doesn't work correctly?
http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.8

-Kevin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,816
Latest member
nipsseyhussle

Latest Threads

Top