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; }
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; }
Are you sure there is a problem with overloading?
Is your compiler output different from mine?-------------- 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
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 ?
This describes a pair of member functions, each named the same, and with identical parameter lists, except one is static.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.
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.