Thread: confusion about overloading

  1. #1
    Registered User
    Join Date
    Mar 2007
    Location
    India
    Posts
    17

    confusion about overloading

    Why overloading is not allowed in below case event though arguments are different?
    how compiler interpret this program.

    Code:
    class Test {    
    static void fun() {}    
    void fun(int i) {} };   
    int main() 
    {    
    Test t;    
    getchar();    
    return 0; 
    }

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    Are you sure there is a problem with overloading?

    -------------- Build: Debug in c sandbox ---------------

    Compiling: main2.cpp
    C:\Documents and Settings\Owner\My Documents\sandbox\c sandbox\main2.cpp:5:10: warning: unused parameter 'i'
    C:\Documents and Settings\Owner\My Documents\sandbox\c sandbox\main2.cpp: In function 'int main()':
    C:\Documents and Settings\Owner\My Documents\sandbox\c sandbox\main2.cpp:9:10: warning: unused variable 't'
    Linking console executable: bin\Debug\c sandbox.exe
    Output size is 29.02 KB
    Process terminated with status 0 (0 minutes, 0 seconds)
    0 errors, 2 warnings
    Is your compiler output different from mine?

  3. #3
    Registered User
    Join Date
    Mar 2007
    Location
    India
    Posts
    17
    sorry i made a wrong posting
    its compiling

    In some post it is stated that

    Member function declarations with the same name and the name parameter-type-list cannot be overloaded if any of them is a static member function declaration.
    so wanted to know why so ?

  4. #4
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    Member function declarations with the same name and the name parameter-type-list cannot be overloaded if any of them is a static member function declaration.
    This describes a pair of member functions, each named the same, and with identical parameter lists, except one is static.

    With your code, the parameter lists are different.

    If the only difference between two member functions is the static keyword, then it would be impossible to know which function should be called. static member functions can be called at any time, even when there is no object available. So they just made that a language violation.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Overloading operators
    By ugmusicbiz in forum C++ Programming
    Replies: 2
    Last Post: 02-13-2009, 01:41 PM
  2. unary operator overloading and classes
    By coletek in forum C++ Programming
    Replies: 9
    Last Post: 01-10-2009, 02:14 AM
  3. Replies: 16
    Last Post: 10-27-2007, 12:42 PM
  4. Inheritance operator overloading
    By global in forum C++ Programming
    Replies: 9
    Last Post: 12-21-2004, 07:03 AM