我试图为了两个不同的目的重载我的函数pointer_move。我通过参数的数量重载它,但它仍然给出错误,调用函数(重载)是不明确的。请帮我解决问题。
#include <iostream>
using namespace std;
int* pointer_move(int *arr, int index, int current_position=0) {
if(current_position < index) {
while(current_position != index) {
arr++;
current_position++;
}
return arr;
} else if(current_position > index) {
while(current_position != index) {
arr--;
current_position--;
}
return arr;
} else {
return arr;
}
}
int* pointer_move(int *arr, int element, int* null, int current_position=0) {
if(current_position < element) {
while(current_position < element) {
arr++;
current_position++;
}
return arr;
} else if(current_position > element) {
while(current_position > element) {
arr--;
current_position--;
}
return arr;
} else {
return arr;
}
}
int main() {
int x[5]={1,32,123,2321,14356};
int *xp=x;
xp=pointer_move(xp, 3);
cout << *xp << endl;
xp=x;
xp=pointer_move(xp, 5, NULL);
cout << *xp << endl;
}