confusion about overloading

This is a discussion on confusion about overloading within the C++ Programming forums, part of the General Programming Boards category; Why overloading is not allowed in below case event though arguments are different? how compiler interpret this program. Code: class ...

  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
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,706
    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
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,706
    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, 12:41 PM
  2. unary operator overloading and classes
    By coletek in forum C++ Programming
    Replies: 9
    Last Post: 01-10-2009, 01: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, 06:03 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21