this is a general question not specific to a program yet so just the void is here
goal. when i print or write some info to a serial port or network port etc the write and print commands take a variity of formats such as a byte, a number, a string and even an array.
so as an example i might have this
lcd.setCursor(10,0);
lcd.print("ALL in ");
lcd.setCursor(5,1);
lcd.print("Error");
i would like to get it down to something like this
MyLCD(10,0,"ALL in ");
MyLCD(5,1,"Error");
void MyLCD(byte col, byte row, ?????? info { \\Here is where i am not sure of the proper datatype for the ?????? so it will take anything just like the print/write does
//do additional stuff here
lcd.setCursor(col,row);
lcd.print(info);
}
MyLCD(5,1,"Error");
void MyLCD(byte col, byte row, ?????? info { \Here is where i am not sure of the proper datatype for the ?????? so it will take anything just like the print/write does
//do additional stuff here
MyLCD(5,1,"Error");
void MyLCD(byte col, byte row, ?????? info { \Here is where i am not sure of the proper datatype for the ?????? so it will take anything just like the print/write does
//do additional stuff here
CMSBridge_ino2:6: error: 'T' has not been declared
CMSBridge_ino2.cpp: In function 'void loop()':
CMSBridge_ino2:246: error: invalid conversion from 'const char*' to 'int'
CMSBridge_ino2:246: error: initializing argument 3 of 'void MyLCD(byte, byte, int)'
zarobhr:
i added that to the code after my void loop
CMSBridge_ino2:6: error: 'T' has not been declared
CMSBridge_ino2.cpp: In function 'void loop()':
CMSBridge_ino2:246: error: invalid conversion from 'const char*' to 'int'
CMSBridge_ino2:246: error: initializing argument 3 of 'void MyLCD(byte, byte, int)'
Did you try putting it before the place where it's used?
zarobhr:
i added that to the code after my void loop
CMSBridge_ino2:6: error: 'T' has not been declared
CMSBridge_ino2.cpp: In function 'void loop()':
CMSBridge_ino2:246: error: invalid conversion from 'const char*' to 'int'
CMSBridge_ino2:246: error: initializing argument 3 of 'void MyLCD(byte, byte, int)'
Did you try putting it before the place where it's used?
no matter where in code i put template<class T> i get the first error that T has not been declared
Is the template class available in the IDE and in which lib does it live? Fungus (short for Funny Gustavo?)? Thank You, that Print function would solve a lot of GLCD printing that I need to do with the UTFT Library
PaulS:
Template functions must be defined in a .h file that is then included in the sketch.
No, they can be in the source.
If you include a header, its contents is placed in the spot of the '#include', so its no different to putting it at the top of the sketch. The compiler just needs to see it before its used.
EDIT: PaulS may be right regarding Arduino specifics, it may only copy the function prototype without the previous 'template' line.
Try putting it all on the one line 'template void MyLCD(byte col, byte row, T t);' though before separating. Had no trouble with template objects, spose functions are a different kettle of tea.