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?
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.
Last edited by ChaosEngine; 05-03-2006 at 07:17 PM.
"I saw a sign that said 'Drink Canada Dry', so I started"
-- Brendan Behan
Free Compiler: Visual C++ 2005 Express
If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?