I have code that looks something like this (compiling using the Arduino IDE).
main sketch file:
#include "myHeader.h"
//setup stuff here, including setting up Serial & SerialBT
loop(){
CheckForMessages(&Serial); //Check USB first
CheckForMessages(&SerialBT); //Then check Bluetooth
}
myHeader.h:
#include "Arduino.h"
//other includes
template void CheckForMessages(T *port);
//declarations of other stuff
myHeader.cpp:
#include "myHeader.h"
template void CheckForMessages(T *port){
if(port->available() !=0){
//rest of function...
}
//definitions of other stuff
When I compile, I get the "undefined reference" errors for both calls to CheckForMessages in the main sketch file. This goes away if I move the definition of the template into the .h file.
I have no issues splitting the declaration and definition of functions in this way as far as I can tell, can anyone explain to me why it isn't working for my templates?
No comments:
Post a Comment