/home/capttawish/Dropbox/cpp/natjecanja/2011/mreza.cpp:34|52|instantiated from here|
/usr/include/c++/4.6/bits/stl_iterator_base_types.h|166|error: no type named ‘iterator_category’ in ‘struct std::pair<int, int>’|
/usr/include/c++/4.6/bits/stl_iterator_base_types.h|167|error: no type named ‘value_type’ in ‘struct std::pair<int, int>’|
/usr/include/c++/4.6/bits/stl_iterator_base_types.h|168|error: no type named ‘difference_type’ in ‘struct std::pair<int, int>’|
/usr/include/c++/4.6/bits/stl_iterator_base_types.h|169|error: no type named ‘pointer’ in ‘struct std::pair<int, int>’|
/usr/include/c++/4.6/bits/stl_iterator_base_types.h|170|error: no type named ‘reference’ in ‘struct std::pair<int, int>’|
||=== Build finished: 5 errors, 0 warnings ===|
That is because instead of using your distance function it is trying to instantiate the distance function in the from the STL (which is why typing "using namespace std;" can flood your namespace). You can fix this by creating your own namespace for that function if you like.
e.g.
1 2 3 4 5 6 7 8 9 10 11
namespace myNamespace{
double distance(pair<int,int> one,pair<int,int> two){
double tmp;
tmp=sqrt(abs(one.first-two.first)*abs(one.first-two.first)+abs(one.second-two.second)*abs(one.second-two.second));
return tmp;
}
}
//... Then when you use your distance fucntion..
mreza[x][y]=mreza[y][x]=myNamespace::distance(dots[x],dots[y]);
> That is because instead of using your distance function it is trying to instantiate the distance function in the from the STL
> (which is why typing "using namespace std;" can flood your namespace).
Actually, not having usingnamespace std ; would make absolutely no difference in this particular case. Koening lookup (aka argument-dependent lookup or ADL ) would result in namespace std being looked up any way. http://en.wikipedia.org/wiki/Argument-dependent_name_lookup