Go Down

Topic: question about void, passing data and print\write (Read 866 times) previous topic - next topic

PaulS

Template functions must be defined in a .h file that is then included in the sketch.

Docedison

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

Bob
--> WA7EMS <--
"The solution of every problem is another problem." -Johann Wolfgang von Goethe
I do answer technical questions PM'd to me with whatever is in my clipboard

fungus

The Arduino IDE is weird about function ordering, it rearranges the code in the sketch before it compiles so that forward references work.

There has to be a way to make it work...you just need somebody who knows more then me about the IDE.

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

pYro_65

#8
Nov 08, 2012, 12:37 am Last Edit: Nov 08, 2012, 12:56 am by pYro_65 Reason: 1

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<class T> 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.

pYro_65

You can do 3 different things I tried.

Code: [Select]
template<class T>
  struct MyLCDHelper{
    static void MyLCD(byte col, byte row, T t)
      {
     
      }
};

//...
MyLCDHelper< bool >::MyLCD( 2, 1, 0 );


Code: [Select]
struct MyLCDHelper{
  template<class T>
    static void MyLCD(byte col, byte row, T t)
      {
       
      }
};

//...
MyLCDHelper::MyLCD( 2, 1, 0 ); //Template auto type deduction.

MyLCDHelper::MyLCD< bool >( 2, 1, 0 ); //Specific template.


Or a not so safe way.

Code: [Select]

//This must be the first line of code.
#define TVoid template<class T> void

TVoid MyLCD(byte col, byte row, T t)
      {

      }

Go Up