templates...C++ code in the .h file
i've been using same file in projects left , right while now. works , works well, i've been told it's bad have code in .h file. reason though, can't make work out template function.
is there better way instead of putting code in .h file have?
eeprom_funcs.h
is there better way instead of putting code in .h file have?
eeprom_funcs.h
code: [select]
#ifndef eepromfuncs_h
#define eepromfuncs_h
#include <eeprom.h>
template<class t>
void writetoeeprom(int address, t& value)
{
union {
t type;
byte b[sizeof(t)];
}
temp;
temp.type = value;
(int = 0; < sizeof(t); i++)
{
eeprom.write(address + i, temp.b[i]);
}
}
template<class t>
void readfromeeprom(int address, t& value)
{
union {
t type;
byte b[sizeof(t)];
}
temp;
(int = 0; < sizeof(t); i++)
{
temp.b[i] = eeprom.read(address + i);
}
value = temp.type;
}
#endif
quote
it works , works well, i've been told it's bad have code in .h file.in general, is. sometimes, though, templates, have to. ignore people dogmatic being wrong.
Arduino Forum > Using Arduino > Programming Questions > templates...C++ code in the .h file
arduino
Comments
Post a Comment