You need to dereference the pointers to return a reference to the object they point to:
*total = *x + *y;
However, in C++ you can use references to facilitate this:
int sum(int x, int y, int& total)
{
total = x + y;
return total;
}
The reference is only declared with total because that is the only argument we need to change. Here's an example of how you would go about calling it:
int a = 5, b = 5;
int total;
sum(a, b, total);
Now that I think of it, since we're using references to change the value, there really isn't a need to return. Just take out the return statement and change the return type to void:
void sum(int x, int y, int& total)
{
total = x + y;
}
Or you can go the other way around and return the addition without using references:
int sum(int x, int y)
{
return x + y;
}
*total = *x + *y(and as a side note, both the x and y pointers should be const, or in-fact not even pointers in this example).