locket23 locket23 - 1 year ago 332
C++ Question

c++ invalid conversion from int* to int

I have the following C++ code:

#include <iostream>

using namespace std;
template<class T>
T f(T x, T y)
return x+y;
int f(int x, int y)
return x-y;
int main()
int *a=new int(3), b(23);
return 0;

I get these errors: invalid conversion from 'int*' to 'int'

initializing argument 1 of 'int f(int, int)' . What does it mean ?


Answer Source

You need to dereference a in your call to f. This is because a is a pointer to an int, while b is a bare int. Dereferencing a pointer to an int returns an int. This results in the function f being called with two ints.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download