I was just wondering if overloading functions is efficient? I'm talking about having 20 overloads of a functions. Would that greatly slow down the program, or does the compiler choose which function to use at compile time?
Printable View
I was just wondering if overloading functions is efficient? I'm talking about having 20 overloads of a functions. Would that greatly slow down the program, or does the compiler choose which function to use at compile time?
20 overloded functions? What function are we talking about? What does it do? If we had some code, we could help you make a smarter decision. It sounds like you could get it to work with a template, but I can't be sure until I see something.
overloaded functions have no effect on runtime.
if you have 3 overloaded functions
the compiler uses name mangling to differentiate the functions. so you end up withCode:void func(void);
void func(int x);
void func(string s);
or something like that (name mangling is implementation dependent)Code:_func_void
_func_int
_func_string
so it shouldn't slow down the program at all.
edit: to be clear, the name mangling occurs at the linker level, so you don't need to worry about it when writing code.