473,414 Members | 1,716 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,414 software developers and data experts.

ambiguous call to overloaded function

Consider the following program:

#include <iostream>

using namespace std;

void print(char c)
{
cout << "from print(char c) : " << c << endl;
return;
}

void print(long c)
{
cout << "from print(long c) : " << c << endl;
return;
}

int main()
{
int i = 100;
print(i);

return 0;
}

When I compile the program I am getting the following compilation
error:

'print' : ambiguous call to overloaded function
could be 'void print(long)'
or 'void print(char)'
while trying to match the argument list '(int)'

int to char requires standard conversion.
But isn't integer promoted to long similar to the way short is
promoted to int ? If int is promoted to long, the ambiguity will not
arise. This is what I expected. But it does not happen. Kindly explain
the reason.

Thanks
V.Subramanian

Sep 10 '07 #1
1 2935
su**************@yahoo.com, India wrote:
Consider the following program:

#include <iostream>

using namespace std;

void print(char c)
{
cout << "from print(char c) : " << c << endl;
return;
}

void print(long c)
{
cout << "from print(long c) : " << c << endl;
return;
}

int main()
{
int i = 100;
print(i);

return 0;
}

When I compile the program I am getting the following compilation
error:

'print' : ambiguous call to overloaded function
could be 'void print(long)'
or 'void print(char)'
while trying to match the argument list '(int)'

int to char requires standard conversion.
But isn't integer promoted to long similar to the way short is
promoted to int ? If int is promoted to long, the ambiguity will not
arise. This is what I expected. But it does not happen. Kindly explain
the reason.
There is no promotion from int to long, it's a conversion. See clause [4.5]
for the list of integral promotions and see clause [4.7] for the definition
of integral conversions.
Best

Kai-Uwe Bux
Sep 10 '07 #2

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

Similar topics

7
by: ishekara | last post by:
Hi, I am having a class template which is used to convert from one type another. I am having a problem when i use the copy constructor with same type. code. #include "stdio.h" template...
1
by: Alex Zhitlenok | last post by:
Hi, My question is how to resolve in C# ambiguous overloaded operators? Let say, I have two unrelated classes A and B, each one implements overloaded operator + with the first parameter of type...
5
by: rolandz | last post by:
Hi, Maybe somebody has been fighting with the problem that I do, currently. I have a class that has method f(). The two versions of the f() method accept different objects: Int and Short. These...
2
by: pvl_google | last post by:
Hi, I'm trying to extend an STL class with additional iterator functionality. In the simplified example below I added an extra iterator class with a dereferencing operator. This operator...
6
by: c1t1z3n | last post by:
hiya, i'm having this weird error on my project. As far as I know "ambiguous call to overloaded function" should only occur when the compiler must choose from several methods, but here i don't think...
4
by: Joseph Turian | last post by:
I have a templated class with the following methods: Vocab(const T& t); Vocab(unsigned uid); However, when T = unsigned, and I call Vocab(unsigned(0)) then the compiler rightly complains about...
1
by: Ruki | last post by:
I want to overload function to swap two others types, for example, type<T>, T* and so on, but I can't compile the following code at VC 6.0. The compiler says : error C2667: 'swap' : none of 2...
8
by: Nikola | last post by:
Hello, I'm writing a String class for C++ and I'm getting the following error message when using operator: test.cpp: In function ‘int main()’: test.cpp:7: error: ISO C++ says that these are...
3
by: mathieu | last post by:
Could someone please tell me what is wrong with the following -ugly- piece of c++ code. Why when I explicititely set the template parameter my gcc compiler start getting confused: bla.cxx: In...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
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...
0
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...
0
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,...
0
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...

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.