Full error code (at compile time)
[Error] @0,0: L6218E: Undefined symbol Fifo<Data, 1000>::addToBuffer(Data) (referred from BUILD/NUCLEO_F429ZI/ARMC6/main.o).
Code:
fifo.h
template <typename T, int Size>
class Fifo{
public:
T buffer[Size];
int in = 0;
int out = 0;
int spaceInBuffer = Size;
int IncrementIn();
int IncrementOut();
void addToBuffer(T);
T popOffBuffer();
};
fifo.cpp (cut out the rest of the class as it probably isn’t relevant)
template <typename T, int Size>
void Fifo<T, Size>::addToBuffer(T obj){
buffer[IncrementIn()] = obj;
}
main.cpp (here is where I use the fifo class
#include "fifo.h"
#define BUFFERSIZE 1000
Fifo<Data, BUFFERSIZE> azureBuffer;
Fifo<Data, BUFFERSIZE> cardBuffer;
EDIT:
The problem was that the template class (Fifo) has to be fully implemented in the header file. Not defined in the header and then implemented in the cpp file. Explaination