I wrote a simple bit array class declared in BitArray.h and defined in BitArray.cpp. I used G++ 2.95.3 20010315 (SuSE) to compile it. When compiled with -DDEBUG a small main function was also compiled, and everything was fine.
However when I use it in programs written in other files, the linker can't find any of the methods, e.g.
int main (int argc, char** argv)
BitArray b(1024); // 1024 bit array
// print bit (0 or 1) at index 0
cout << b.bitAt (0) << endl;
// find index of first occurence of bit
// 1 starting at index 0
cout << b.findBit (0, 1) << endl;
When I compile with the following
g++ -c BitArray.cpp
g++ test.cpp BitArray.o
/tmp/cc31oTBq.o: In function `main':
/tmp/cc31oTBq.o(.text+0x2f): undefined reference to `BitArray::bitAt(unsigned int) const'
collect2: ld returned 1 exit status
However the exact same code in the main function in BitArray.cpp works.
Can anyone tell me what's going on?!!