Go Down

Topic: Function Overloading (Read 2184 times) previous topic - next topic

prizepony

Feb 25, 2008, 09:50 pm Last Edit: Feb 25, 2008, 09:51 pm by prizepony Reason: 1
Is it possible to do function overloading or function polymorphism in custom libraries in Arduino? I currently have a library written (not a class) that simply includes a bunch of important functions and defined values. I want one of these functions to have the ability to take not only 1 parameter but 2 parameters in certain situations.

Is this possible in Arduino? Does a class need to be made in order to do this? If so, does anyone have any example of this I can look at?

Thank you.

mellis

It is possible as long as the file containing the functions is compiled as C++ (i.e. has the .cpp extension).  You should be able to just declare both forms of the function as normal, and the right one will be selected based on the number of parameters in the call to it.

prizepony

That simple change worked. Thank you.

Go Up