Thread: what's an overloaded function ?

  1. #1
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020

    what's an overloaded function ?

    what's an overloaded function ? why ar they useful ?

    thnx

  2. #2
    Unregistered
    Guest
    An overloaded function is a function with the same name that performs different operations on different data. So instead of having
    void calcFloat(float x, float y, float z);
    void calcInt(int x, int y, int z);
    void calcTwoInt(int x, int y);

    you could use

    void calcNum(float x, float y, float z);
    void calcNum(int x, int y, int z);
    void calcNum(int x, int y);

    Instead of using several function names and confusing yourself you can use a single function name with different parameters according to how you want the data handled. Think of printf, that's a version of overloaded function because it can take different types and numbers of arguments and handle them accordingly. Though overloaded functions are a bit harder to implement in C than C++.

  3. #3
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    how do u create an overloaded function ? DOesn't there have to be a fixed number of parameters ? How does the function check it ?

  4. #4
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,823
    > how do u create an overloaded function

    You use C++.

    C can't do overloaded functions.

  5. #5
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    k thnx

  6. #6
    Unregistered
    Guest
    C can do overloaded functions, but you have to get into variable lenth argument lists and have a lot of conditional programming inside of one function. In C++ you have several functions with the same name, but in C you have one function that can do calculations on all kinds of data. Usually it's not worth it in C.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 08:28 AM
  2. Replies: 3
    Last Post: 06-04-2008, 05:57 PM
  3. dllimport function not allowed
    By steve1_rm in forum C++ Programming
    Replies: 5
    Last Post: 03-11-2008, 03:33 AM
  4. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  5. Cannot resolve overloaded function
    By Mithoric in forum C++ Programming
    Replies: 10
    Last Post: 11-29-2003, 03:40 AM