I want to determine if the element in vector is average between its neighbours so I wrote this program
#include <iostream>
#include <vector>
using namespace std;
template <typename T>
bool is_avg(vector<T>::iterator x) { <-- error line
T l = *(x - 1), m = *x, r = *(x + 1);
return x * 2 == l + r;
}
int main() {
vector<int> v;
v.push_back(2);
v.push_back(3);
v.push_back(4);
cout << (is_avg(v.begin() + 1) ? "Yes" : "No");
return 0;
}
But it doesn't work
main.cpp|6|error: template declaration of 'bool is_avg'
What is wrong?