Thread: Overloading functions

  1. #1
    Registered User mrafcho001's Avatar
    Join Date
    Jan 2005

    Overloading functions

    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?
    My Website
    Add Color To Your Code!

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    United States
    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.

  3. #3
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Chch, NZ
    overloaded functions have no effect on runtime.
    if you have 3 overloaded functions
    void func(void);
    void func(int x);
    void func(string s);
    the compiler uses name mangling to differentiate the functions. so you end up with
    or something like that (name mangling is implementation dependent)

    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?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Is it legal to have functions within functions?
    By Programmer_P in forum C++ Programming
    Replies: 13
    Last Post: 05-25-2009, 11:21 PM
  2. Shell functions on Win XP
    By geek@02 in forum Windows Programming
    Replies: 6
    Last Post: 04-19-2004, 05:39 AM
  3. Inline functions and inheritance
    By hpy_gilmore8 in forum C++ Programming
    Replies: 3
    Last Post: 01-14-2004, 06:46 PM
  4. Passing pointers between functions
    By heygirls_uk in forum C Programming
    Replies: 5
    Last Post: 01-09-2004, 06:58 PM
  5. illegal function overloading????
    By Mr_Jack in forum C++ Programming
    Replies: 3
    Last Post: 12-17-2003, 01:03 PM