Need some help with inheritence with STL

P

pb

Im getting this compile error,
undefined reference to BitString<10>::scramble()
collect2: ld returned 1 exit status

For some reason the compiler cant find the symbol for the member function i
declare. Everythign compiles correctly up to the point when i make a call to
the "scramble" routine. Calling the member functions of the base class work
just fine, but when i try to call the member functions i declare in the
extened class, the linker cant find the symbols. any ideas?

thx for the help...

// BitString.h

#include <bitset>
using namespace std;

template <size_t N>
class BitString : public bitset <N> {
public:
Bitstring <N>():bitset<N>(){};
void scramble();
};

//Bitstring.cpp

template <size_t N>
BitString<N>::scramble()
{
return;
}

// main.cpp
#include "BitString.h"
int
main()
{
BitString<10> data;
data.scramble()
return;
}
 
D

David Harmon

On Wed, 17 Nov 2004 21:44:08 -0800 in comp.lang.c++, "pb"
Im getting this compile error,
undefined reference to BitString<10>::scramble()

This issue is covered in Marshall Cline's C++ FAQ. See the topics
"[34.12] Why can't I separate the definition of my templates class
from it's declaration and put it inside a .cpp file?" and
"[34.13] How can I avoid linker errors with my template functions?".
It is always good to check the FAQ before posting. You can get the
FAQ at:
http://www.parashift.com/c++-faq-lite/
 

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,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top