473,729 Members | 2,409 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Overload Resolution in C++

Can someone explain me how overload resolution works in C++?

For example if I have function void f(char, int); and I will call
f('A', 3.1) or f(1.5, 3.1F) what would be the result?

Thanks
Oct 29 '08 #1
2 2703
zb******@szymcz yk.eu wrote:
Can someone explain me how overload resolution works in C++?

For example if I have function void f(char, int); and I will call
f('A', 3.1) or f(1.5, 3.1F) what would be the result?
If you only have a single function called 'f', no overload is present.
Overload is only there if you have more than one function named 'f':

void f(char, int);
void f(long, double);

int main() {
f(0L, 0.0); // the latter is called
f('c', 42); // the former is called
}

Explaining how overload resolution "works" can take weeks. Please find
a decent C++ book and read the section/chapter on overloading.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Oct 29 '08 #2
On Oct 29, 3:06*pm, Victor Bazarov <v.Abaza...@com Acast.netwrote:
zbign...@szymcz yk.eu wrote:
Can someone explain me how overload resolution works in C++?
For example if I have function void f(char, int); and I will call
f('A', 3.1) or f(1.5, 3.1F) what would be the result?

If you only have a single function called 'f', no overload is present.
Overload is only there if you have more than one function named 'f':

* * *void f(char, int);
* * *void f(long, double);

* * *int main() {
* * * * *f(0L, 0.0); // the latter is called
* * * * *f('c', 42); // the former is called
* * *}

Explaining how overload resolution "works" can take weeks. *Please find
a decent C++ book and read the section/chapter on overloading.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Indeed. However, there are some rules that are followed, which are not
that complicated.
Try looking:
http://accu.org/index.php/journals/268
Oct 29 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2091
by: Richard Hayden | last post by:
Hi, I have the following code for example: /**********************************/ #include <iostream> class C1 { public:
1
1883
by: M Jared Finder | last post by:
What are the rules for method overload resolution when there are functions with a params argument? No mention of params is made in section 7.4.2 of the C# specification on MSDN (titled "Overload Resolution"). -- MJF
13
2732
by: Vladimir Granitsky | last post by:
Hi guys, Please, look at the code below and try to step into it. The compiled code calls the loosely typed method public void Method1(object o) !?!? Am I right that C# compiler does wrong overload resolution ? I've used parameters of type object and string here, just to illustrate the problem. Really I have a bit more deep inheritance graph, and the things get more interesting if the strongly typed overload is like override public void...
0
2606
by: Eph0nk | last post by:
Hi, I get an overload resolution failed error (Overload resolution failed because no accessible 'New' can be called without a narrowing conversion), and I can't seem to find a lot of relevant information by googling the web. Function GetFromXml(Id As String, Node As String) Dim NodeValue As String Dim xpathDoc As XPathDocument Dim xmlNav As XPathNavigator Dim xmlNI As XPathNodeIterator
2
1851
by: Michi Henning | last post by:
Hi, the following code produces an error on the second-last line: Interface Left Sub op() End Interface Interface Right Sub op(ByVal i As Integer)
3
1528
by: Christof Nordiek | last post by:
Given the following code Is there any way to call one of the Bar methods. using System; class Program { static void Main() { Foo<string, stringfoo = new Foo<string,string>();
1
3719
by: =?Utf-8?B?QU1lcmNlcg==?= | last post by:
I have a strange situation with vb 2005 regarding option strict that looks like a compiler bug to me. Consider: Dim f1 As New Font("Arial", 8.25) Dim f2 As New Font("Arial", 8.25, FontStyle.Bold) ' f1 is ok with option strict on or off ' f2 is ok with strict on, but with off I get an overload resolution failure The complete diagnostic is:
2
1867
by: xtrigger303 | last post by:
Hi to all, I was reading Mr. Alexandrescu's mojo article and I've a hard time understanding the following. Let's suppose I have: //code struct A {}; struct B : A {};
5
3695
by: jknupp | last post by:
In the following program, if the call to bar does not specify the type as <int>, gcc gives the error "no matching function for call to ‘bar(A&, <unresolved overloaded function type>)’". Since bar explicitly takes a pointer-to-member with no parameters, why is the lookup for the overloaded function not able to use the number of arguments to determine the appropriate function? Is there a relevant portion of the standard that governs the...
0
8921
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8763
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9284
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9202
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9148
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8151
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6022
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3238
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2165
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.