Hi,
I try to build a class method that will accept any datatype as parameter. I use a template like this in my .cpp file:
template <typename DataStruct> bool EEPROM_Manager::write_anythingEE(int addr, DataStruct wert) {
return eeprom_write_anything(addr, wert);
}
the method calls a private method:
template <typename DataStruct> bool EEPROM_Manager::eeprom_write_anything(int addr, DataStruct wert) {
EEPROM.put(addr,wert);
return true;
}
I can access other methods of my class. The definitions in my header file:
class EEPROM_Manager {
private:
template <typename DataStruct> bool eeprom_write_anything(int addr, DataStruct wert);
...
public:
EEPROM_Manager();
...
template <typename DataStruct> bool write_anythingEE(int addr, DataStruct wert);
};
In the .ino file I call the method like this:
EEPROM_Manager myWriter;
PERSON somePerson;
strcpy(somePerson.firstname, "Piet");
strcpy(somePerson.lastname, "Pietersen");
somePerson.phonenumber = 123456789;
strcpy(somePerson.address, "Here and there");
myWriter.write_anythingEE(0,somePerson);
This returns an undefined reference error:
Arduino: 1.8.8 (Mac OS X), TD: 1.45, Board: "Teensy 3.2 / 3.1, Serial, 96 MHz (overclock), Faster, US English"
.../eeprom_writer.ino.cpp.o: In function `setup':
.../eeprom_writer.ino:33: undefined reference to `bool EEPROM_Manager::write_anythingEE<PERSON>(int, PERSON)'
Seems to me that the compiler is looking for a method with the type PERSON as parameter ignoring the use of the template?!
Any ideas?