The code is below. The code does not compile on an online compiler, and I have no idea why. It is short and pretty self-explanatory, please look below for details.
#include <iostream>
#include <cmath>
using namespace std;
int N;
int distance(int a, int b){
if(abs(a-b) > N/2){
return N - abs(a-b);
}
return abs(a-b);
}
bool test(int x, int y){
if(distance(x,y) <=2){
return true;
}
return false;
}
int main()
{
N = 2;
cout << "Hello World" << endl;
cout << test(3,4) << endl;
return 0;
}
Error message below:
In file included from /usr/include/c++/4.8.3/bits/stl_algobase.h:65:0,
from /usr/include/c++/4.8.3/bits/char_traits.h:39,
from /usr/include/c++/4.8.3/ios:40,
from /usr/include/c++/4.8.3/ostream:38,
from /usr/include/c++/4.8.3/iostream:39,
from main.cpp:1:
/usr/include/c++/4.8.3/bits/stl_iterator_base_types.h: In instantiation of 'struct std::iterator_
traits<int>':
/usr/include/c++/4.8.3/bits/stl_iterator_base_funcs.h:114:5: required by substitution of 'templ
ate<class _InputIterator> typename std::iterator_traits<_Iterator>::difference_type std::distance
(_InputIterator, _InputIterator) [with _InputIterator = int]'
main.cpp:15:20: required from here
/usr/include/c++/4.8.3/bits/stl_iterator_base_types.h:165:53: error: 'int' is not a class, struct
, or union type
typedef typename _Iterator::iterator_category iterator_category;
^
/usr/include/c++/4.8.3/bits/stl_iterator_base_types.h:166:53: error: 'int' is not a class, struct
, or union type
typedef typename _Iterator::value_type value_type;
^
/usr/include/c++/4.8.3/bits/stl_iterator_base_types.h:167:53: error: 'int' is not a class, struct
, or union type
typedef typename _Iterator::difference_type difference_type;
^
/usr/include/c++/4.8.3/bits/stl_iterator_base_types.h:168:53: error: 'int' is not a class, struct
, or union type
typedef typename _Iterator::pointer pointer;
^
/usr/include/c++/4.8.3/bits/stl_iterator_base_types.h:169:53: error: 'int' is not a class, struct
, or union type
typedef typename _Iterator::reference reference;