473,809 Members | 2,617 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

some problems about exact match in the overload resolution.

Hi everyone.

In the following program, foo is an ambiguous call.

#include <iostream>
using namespace std;

void foo(int *);
void foo(int (&)[5]);

int main()
{
int arr[5] = {0, 1, 2, 3, 4};

foo(arr);

return 0;
}

why?
void foo(int (&)[5]); is an exact match
void foo(int (&)[5]); require an array to pointer conversion.

Regards.

Jul 29 '07 #1
2 1562
Wayne Shu wrote:
Hi everyone.

In the following program, foo is an ambiguous call.

#include <iostream>
using namespace std;

void foo(int *);
void foo(int (&)[5]);

int main()
{
int arr[5] = {0, 1, 2, 3, 4};

foo(arr);

return 0;
}

why?
void foo(int (&)[5]); is an exact match
void foo(int (&)[5]); require an array to pointer conversion.
You mean foo(int*) requires the conversion...

No, foo(int(&)[5]) is not an exact match. It requires binding
of a reference. An exact match would be a function with an array
as the argument, which is impossible.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 29 '07 #2
On Jul 29, 2:58 pm, Wayne Shu <Wayne...@gmail .comwrote:
In the following program, foo is an ambiguous call.
#include <iostream>
using namespace std;
void foo(int *);
void foo(int (&)[5]);
int main()
{
int arr[5] = {0, 1, 2, 3, 4};

foo(arr);

return 0;

}
why?
void foo(int (&)[5]); is an exact match
Actually, it's what the standard calls an lvalue transformation.
void foo(int (&)[5]); require an array to pointer conversion.
You mean "foo( int* )", of course. For purposes of overload
resolution, the standard considers it an lvalue transformation
as well; for purposes of ranking, both are considered exact
matches. There are additional considerations which can be taken
into account, but none apply here.

--
James Kanze (Gabi Software) email: ja*********@gma il.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Jul 29 '07 #3

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

Similar topics

2
2070
by: -Steve- | last post by:
Okay I have a bunch of code below. Hope it comes across readable. The problem I'm having is that in the lines under main(): cout << a << endl; Is going into the code for IntArray(const IntArray&);. Without that function these first 5 tests work fine. Of course I need that come test6(). Also something must be wrong with the deconstructor. If I comment it out my
1
1500
by: Piotre Ugrumov | last post by:
I have some problems and some doubts. I have implemented a class hierachy. The base class Velivolo, from Velivolo derive Militare and Civile, from militare derive Aereo and Elicottero, from Civile derive Passeggero e Merce. In every class I have implemented the overload of << and >>. In a class Simulator (not in hierachy) I have implemented the overload of << in this way: ostream &operator<<(ostream &out, const Simulatore &s){...
193
9658
by: Michael B. | last post by:
I was just thinking about this, specifically wondering if there's any features that the C specification currently lacks, and which may be included in some future standardization. Of course, I speak only of features in the spirit of C; something like object-orientation, though a nice feature, does not belong in C. Something like being able to #define a #define would be very handy, though, e.g: #define DECLARE_FOO(bar) #define...
13
2735
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
2611
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
1861
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)
2
9793
by: Arvid Requate | last post by:
Hello, I'd like to understand why the following code does not compile. It looks like a strangeness in connection with overload resolution for the <complex> header: The conversion operator double() of class B is called for the member complex::operator*=(double) as expected, but not for operator*(complex, double). The effect is, that the template matching (or overload resolution)
3
1530
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>();
2
2708
by: zbigniew | last post by:
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
0
10376
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...
0
9200
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...
1
7662
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6881
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();...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5689
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4332
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
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3015
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.