473,386 Members | 1,602 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

overloaded function question

consider overloaded functions
//function 1
void hi(int a)
{
}

//function 2
void hi(int a, int b = 20)
{
}

int main()
{
hi(10);
}

which function will it be invoked and y.
Aug 22 '08 #1
6 1221
JosAH
11,448 Expert 8TB
Please give your topics proper titles; 'hi' is not a proper subject title.
I have changed your other topic titles (all were named 'hi'). Don't do that anymore.

kind regards,

Jos (mod)
Aug 22 '08 #2
Banfa
9,065 Expert Mod 8TB
Well I would suggest you try compiling your example and see what it does. Just add some cout statements to you functions so you can see which one is called.

If you manage to get you code to compile without error then you can run it and find out which one is called then you can begin to attempt an explanation of why.
Aug 22 '08 #3
Well I would suggest you try compiling your example and see what it does. Just add some cout statements to you functions so you can see which one is called.

If you manage to get you code to compile without error then you can run it and find out which one is called then you can begin to attempt an explanation of why.
thanks for ur reply i tried this will raise to compiler error informing ambiguity.
Aug 22 '08 #4
Please give your topics proper titles; 'hi' is not a proper subject title.
I have changed your other topic titles (all were named 'hi'). Don't do that anymore.

kind regards,

Jos (mod)
hi iam new to this forum so i will post a proper one ...
Aug 22 '08 #5
Banfa
9,065 Expert Mod 8TB
thanks for ur reply i tried this will raise to compiler error informing ambiguity.
Correct :-) and that is your answer, the question which one will be called is pointless because the compiler will not compile it so neither will be called.

You have to make the function call unambiguous in this case either by removing the default parameter on the second overload or examining why there are 2 overloads and removing one of them.
Aug 22 '08 #6
SpecialKay
109 100+
i cant imagin why you would ever need to do something like this.
but you have your answer.
Aug 22 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Nitin Bhardwaj | last post by:
Thanx in advance for the response... I wanna enquire ( as it is asked many a times in Interviews that i face as an Engg PostGraduate ) about the overloading capability of the C++ Language. ...
4
by: masood.iqbal | last post by:
Please help me with this doubt that I have regarding overloaded operators. Sometimes they are member functions and sometimes they are friends (e.g. see the code snippet from Stroustrup, Second...
20
by: modemer | last post by:
Question is as in subject. For example: class BaseClass { public: void func() { do something; } // I don't want this function being overloaded in its inherited class };
44
by: bahadir.balban | last post by:
Hi, What's the best way to implement an overloaded function in C? For instance if you want to have generic print function for various structures, my implementation would be with a case...
7
by: cmay | last post by:
Can someone quick shed some light on this issue I am having? I wanted to create 2 constructors for my object, one that takes an ID value and one that takes a datarow. If ID value is provided,...
4
by: Vish | last post by:
Hi all, I am having a build error in one of the overloaded functions in my class. The function takes either a string as a parameter or a type referenced in another dll as a parameter. My class...
2
by: B. Williams | last post by:
I have an assignment for school to Overload the operators << and >and I have written the code, but I have a problem with the insertion string function. I can't get it to recognize the second of...
2
by: desktop | last post by:
If a function should work with different types you normally overload it: void myfun(int a){ // do int stuff } void myfun(std::string str){ // do string stuff }
2
by: subramanian100in | last post by:
overloaded operator=() -------------------------------- overloaded assignment operator should be a non-static MEMBER function of a class. This ensures that the first operand is an lvalue. If...
9
by: Lawrence Krubner | last post by:
Possibly a dumb question but is type hinting allowed with overloaded methods? Can one class have these two methods? public function doSelect(Criteria $c) { // some code here } public...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.