Call of Overloaded Function Is Ambiguous

Call of overloaded function is ambiguous

The literal 0 has two meanings in C++.

On the one hand, it is an integer with the value 0.

On the other hand, it is a null-pointer constant.

As your setval function can accept either an int or a char*, the compiler can not decide which overload you meant.

The easiest solution is to just cast the 0 to the right type.

Another option is to ensure the int overload is preferred, for example by making the other one a template:

class huge
{
private:
unsigned char data[BYTES];
public:
void setval(unsigned int);
template <class T> void setval(const T *); // not implemented
template <> void setval(const char*);
};

Why is this call to the overloaded function ambiguous?

The compiler sees an ambiguous call to the following two constructors (note that neither of them take an initializer list):

template <class InputIt>
std::vector::vector (InputIt first, InputIt last, const Allocator& alloc = Allocator());

and

template <class InputIt>
std::string::string (InputIt first, InputIt last, const Allocator& alloc = Allocator());

Now, if you were to actually call the std::string constructor with those iterator arguments you'd get an error, because they don't dereference to a char. But since that check is not part of the function declaration (e.g. via SFINAE), you're getting the ambiguity error instead.

C++ Call of overloaded function is ambiguous

Your problem is that you declare the functions in the namespace excercises, then you add using namespace exercises;, after that you declare them again in the default namespace. Due to the using-directive, the compiler does not know, which version of the declaration to refer to, the ones declared inside the namespace or the ones declared in the default namespace.

The functions declared in the namespace exercises remain undefined, you only define the ones in the default namespace.

Try solving the problem first without namespace usage, then add the namespace but do not use the using namespace declaration.

Call of overloaded function is ambiguous even with different argument order

You give two integers, so the compiler have to convert one into a float, but which function shall be taken?

int main()
{
fun(20.0,20);
fun( 20, 20.0);
}

these calls makes the compiler happy, since you tell which function shall be taken.

error: call of overloaded function ambiguous

You can find in the last few words that

fstream.h:43:132: error: call of overloaded 'ioctl(const char*&, int&, uintptr_t)' is ambiguous 43 | inline int ioctl (const char* rname, int request, void* argument) { return fstream::ioctl (rname, request, uintptr_t(argument)); }

intptr_t is actually a uintptr_t in your environment. And as for uintptr_t, you can find in cppreference that it's an unsigned integer.

According to ranking of implicit conversion sequence in overload resolution, unsigned sth => long and unsigned sth => int are equivalent(both conversion). So no winner, all loser, which leads to compilation error.

If you just want to avoid compilation error, convert intptr_t to long helps. But I think the best way is to use proper type that stands for its meaning. For example, if it's for an address, then just use uintptr_t in the beginning, and make it a convention.

Call of Overloaded Functions is Ambiguous

Just remove the constructor which takes no parameters. The second constructor already does everything the first constructor does.

If it receives a nullptr, it tests it and sets the local variable, if not it continues with its logic. The first constructor is completely superfluous.

Deleting overloaded function. C++11. Call of overloaded ... is ambiguous

When you call

func(2.3)

you pass a double to the function. The list of candidates contains both func(int) and func(char), as overload resolution happens before delete kicks in:

If the function is overloaded, overload resolution takes place first, and the program is only ill-formed if the deleted function was selected Ref: cppreference.com, see Avishai's answer for precise standard quotes.

Now double can be converted both to char and int, hence the ambiguity.

Without deleting function with char arguments double was converted to int and func(int) was called, why now it is forbidden?

You get an ambiguity error even without deleteing the char version, see live here. Of course if you only define the func(int), then there will be no ambiguity so double will happily be converted to an int.

Call of overloaded function is ambiguous... But Why? Template problem

As mentioned in the comment you should do some changes to remove the ambiguity between the std::swap and yours. remove using namespace std; and use std:: before cout:

#include <iostream>

template<typename T>
void swap(T &a, T &b)
{
T dummy = a;
a = b;
b = dummy;
}
template<typename T>
void swap(T a[], T b[], int size)
{
for(int i = 0; i < size;i++)
{
T dum = a[i];
a[i] = b[i];
b[i] = dum;
}
}
int main()
{
int a = 20;
int b = 10;
swap(a, b);
std::cout << "a: " << a << "\t" << "b: " << b << std::endl;

int eights[] = {8, 8, 8, 8, 8, 8, 8};
int threes[] = {3, 3, 3, 3, 3, 3, 3};
for(int i = 0; i <7;i++)
{
std::cout << eights[i] << "\t";

}
for(int i = 0; i <7;i++)
{
std::cout << threes[i] << "\t";

}

swap(eights, threes, 7);
for(int i = 0; i <7;i++)
{
std::cout << eights[i] << "\t";

}
for(int i = 0; i <7;i++)
{
std::cout << threes[i] << "\t";

}
}


Related Topics



Leave a reply



Submit