ajay bidari
ajay bidari

Reputation: 723

function overloading ambiguity in c++

I have two functions with the signatures as below.

void overloading(int, int)

and

void overloading(int, A *ptr, int)

where A is a class.

When I am compiling in gcc 3.4. My main function has the following call.

A *pointer = new A();

overloading(10, pointer,20);

I get an error which says

"Invalid conversion from A * to int" 

Am I doing something wrong or the compiler is not able to identify the correct overloaded function?

Upvotes: 0

Views: 940

Answers (1)

Mark B
Mark B

Reputation: 96301

Your problem is that at the location you may the call to overloading you haven't declared the three parameter version of the function so the compiler only sees the (int, int) version. You can even prove this by pre-processing the source file (for example g++ -E).

Just make sure to include all the needed headers in your main file.

Upvotes: 2

Related Questions