Nov 14, 2017 at 12:25am UTC
I have a function that I am passing a character to, however I want the function to return a an Integer. Should I do this through a template? Or if I overload the function would that work?
Last edited on Nov 14, 2017 at 12:26am UTC
Nov 14, 2017 at 12:38am UTC
Simply write a function which accepts a char and returns an Integer
Integer f(char ) { ... }
Nov 14, 2017 at 12:59am UTC
Ok, I was under the impression that a function could only accept and return one data type
Nov 14, 2017 at 2:56am UTC
Ok, I was under the impression that a function could only accept and return one data type
Overloading applies when there are multiple functions with the same name, accepting different data types.
See:
https://en.wikipedia.org/wiki/Function_overloading
Function templates are instructions to the compiler, describing how to write overloaded functions for you.
Last edited on Nov 14, 2017 at 2:56am UTC