Ok so i think the way i should implement this is with a templated function.
i probably should of explained a bit more of what i was doing but anyway.
this is part of my original code, for reading from an eeprom chip.
byte at93c::readbyte(int address){
byte datain;
int _address = (address << (16 - _addresslength));
digitalWrite(_cspin, HIGH);
_shiftOut(_dopin, _skpin, B110, 3);
_shiftOut(_dopin, _skpin, _address, _addresslength);
datain = _shiftIn(_dipin, _skpin, MSBFIRST, _datalength);
digitalWrite(_cspin, LOW);
return datain;
}
word at93c::readword(int address){
word datain;
int _address = (address << (16 - _addresslength));
digitalWrite(_cspin, HIGH);
_shiftOut(_dopin, _skpin, B110, 3);
_shiftOut(_dopin, _skpin, _address, _addresslength);
datain = _shiftIn(_dipin, _skpin, _datalength);
digitalWrite(_cspin, LOW);
return datain;
}
Based either on the setting of an organisation pin or the design of the part each address stores/reads either 8 bits or 16bits.
What I want to get rid of is duplicating function read for bytes or words.
for writing to the chip, the data type (byte/word) can be inferred from the data passed to the writing function.
as in the example given by Nick
template<typename T> T add (const T x, const T y)
{
return x + y;
} // end of add
the problem i face is for reading the data the returned type cannot be inferred from the arguments but must come from a the organisation variable (org) given in the contructor.
i.e
if org = 8 read(int address) returns byte
if org = 16 read(int address) returns word