+ 33

Is it allowed in c++ to have two functions with same name?

18th Oct 2016, 6:31 PM
Jaya
66 ответов
+ 76
Yes, it's called function overloading. Multiple functions are able to have the same name if you like, however MUST have different parameters. void func(int a, int b) { } void func(float a, int b) { } void func(int a, int b, int c) { } Here we have overloaded function "func", and will all work within the same program. When calling the function, the program will run the function which corresponding to the arguements you pass through. For example, if you called func(5.5, 6), it would run the second function.
18th Oct 2016, 6:52 PM
Cohen Creber
Cohen Creber - avatar
+ 23
Cohen Creber described the subject completely but with a simple NOTE !!! Be careful that when overloading a function only changing the return value with the same name and parameters is NOT an overloading, it is an ERROR. In other word return value change in overloading doesn't count. int func() {} void func() {} is an ERROR.
19th Oct 2016, 10:15 PM
TwinChrist
+ 8
Yes as long as the function in question is defined differently by its parameters. Either using a different type or different number of arguments. This will work: void func(int a,int b){} void func(int a,int b, int c){} void func(float a, float b){} This will not: void func(int a, int b){} void func(int x, int y){}
9th Nov 2016, 8:32 PM
Lynette Lee-Ann Everson
Lynette Lee-Ann Everson - avatar
+ 8
Yes,with different arguments(function overloading)
19th Mar 2017, 3:46 PM
Sreerag V S
Sreerag V S - avatar
+ 6
Thanks ☺
18th Oct 2016, 7:27 PM
Jaya
+ 6
Yes,but want to use different parameters. for example, int function(int a,int b); int function(float c,int d); Simply,called function overloading.
26th Nov 2016, 10:42 AM
Sreerag V S
Sreerag V S - avatar
+ 5
Yes ,it is oop.In every oop there is polymorphism i.e Overloading and overriding
27th Nov 2016, 9:13 AM
"$uraj @nbhule "
"$uraj @nbhule " - avatar
+ 4
yes
1st Dec 2016, 9:39 AM
Nguyễn Hoàng Long
Nguyễn Hoàng Long - avatar
+ 3
but different parameters list
26th Nov 2016, 6:32 AM
~Sudo Bash
~Sudo Bash - avatar
+ 3
Yes! It is possible to use two or more function with same name in c++. First I want to explain function overloading: Function overloading is concept which allow to user to define two or more functions with the same name but with a different set of parameters. Hence we can use two more function with same name using function overloading concept.
26th Nov 2016, 11:57 AM
Pushpendra Chandrawanshi
Pushpendra Chandrawanshi - avatar
+ 3
i think she is got it so dont write too much comments on a very basic questions peoples !
27th Nov 2016, 2:21 AM
~Sudo Bash
~Sudo Bash - avatar
+ 3
yes it is possible the functions with same name but with different parameters ...if we change the return type only it doesn't effect....so we have to change parameters or just their return types
28th Nov 2016, 3:11 PM
sudhir meena
sudhir meena - avatar
+ 3
Yes, it is possible. It is called function overloading. Same function name but different parameters. For example, void sum(int a, int b) {} void sum(float a, float b) {}
29th Nov 2016, 10:58 AM
Debalina Mukherjee
Debalina Mukherjee - avatar
+ 3
yes
1st Dec 2016, 9:40 AM
Alhamdulillah Syed Hozaifa Ali
Alhamdulillah Syed Hozaifa Ali - avatar
+ 3
yes, that is called function overloading, Function overloading in C++ You can have multiple definitions for the same function name in the same scope
23rd Jan 2017, 6:49 PM
meherDev
meherDev - avatar
+ 2
yes u can have multiple functions with same name. the only condition is that these functions need to have different parameters. this feature is called function overloading.
25th Nov 2016, 3:49 PM
Siddhesh Shirsat
Siddhesh Shirsat - avatar
+ 2
Yes...And It is called Function Overloading. U can have same function name but with different parameters....!!!
25th Nov 2016, 4:19 PM
rohit bisht
rohit bisht - avatar
+ 2
Yes, use function overloading what the other said or use template<typename T>.
27th Nov 2016, 1:51 AM
Max_N
Max_N - avatar
+ 2
Yah its possible with a simple concept called Function Overloading!!
27th Nov 2016, 10:55 AM
Aniket kinhikar
Aniket kinhikar - avatar
+ 2
yes it is possible with the concept of function overloading. where functions wit same name but different parameters or parameter count are considered to be different functions eg. int a() & int a(int b) are different void a(int b) & void a(float b) are different
28th Nov 2016, 4:34 PM
Pradeep G
Pradeep G - avatar