[英]Boost 1.65.1 geometry distance strategy compile error with Visual Studio 2017
[英]boost geometry distance() error in compile
我只想寫一個由boost給出的簡單示例( http://www.boost.org/doc/libs/1_52_0/libs/geometry/doc/html/geometry/quickstart.html )。 編譯期間有一些錯誤。 我使用eclipse和Mingw來編譯它。 有人能告訴我這是什么問題嗎?
測試代碼如下:
#include <iostream>
using namespace std;
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/algorithms/distance.hpp>
using namespace boost::geometry;
int main() {
cout << "!!!Hello World!!!" << endl;
model::d2::point_xy<int> p1(1, 1), p2(2, 2);
cout << "Distance p1-p2 is: " << distance(p1, p2) << endl;
return 0;
}
錯誤如下:
c:\program files\mingw64\bin\../lib/gcc/x86_64-w64-
mingw32/4.7.1/include/c++/bits/stl_iterator_base_funcs.h:114:5:
required by substitution of 'template<class _InputIterator>
typename std::iterator_traits::difference_type
std::distance(_InputIterator, _InputIterator) [with _InputIterator
= boost::geometry::model::d2::point_xy<int>]'
..\src\test.cpp:22:50: required from here
c:\program files\mingw64\bin\../lib/gcc/x86_64-w64-
mingw32/4.7.1/include/c++/bits/stl_iterator_base_types.h:166:53:
error: no type named 'iterator_category' in 'class
boost::geometry::model::d2::point_xy<int>'
c:\program files\mingw64\bin\../lib/gcc/x86_64-w64-
mingw32/4.7.1/include/c++/bits/stl_iterator_base_types.h:167:53:
error: no type named 'value_type' in 'class
boost::geometry::model::d2::point_xy<int>'
c:\program files\mingw64\bin\../lib/gcc/x86_64-w64-
mingw32/4.7.1/include/c++/bits/stl_iterator_base_types.h:168:53:
error: no type named 'difference_type' in 'class
boost::geometry::model::d2::point_xy<int>'
c:\program files\mingw64\bin\../lib/gcc/x86_64-w64-
mingw32/4.7.1/include/c++/bits/stl_iterator_base_types.h:169:53:
error: no type named 'pointer' in 'class
boost::geometry::model::d2::point_xy<int>'
c:\program files\mingw64\bin\../lib/gcc/x86_64-w64-
mingw32/4.7.1/include/c++/bits/stl_iterator_base_types.h:170:53:
error: no type named 'reference' in 'class
boost::geometry::model::d2::point_xy<int>'
這就是為什么你應該保留使用指令。 你有:
using namespace std;
using namespace boost::geometry;
將這些名稱空間中的所有名稱拖動到全局名稱空間中。 這包括std::distance
和boost::geometry::distance
和(從錯誤消息判斷) std::distance
被選為更好的重載。
如果刪除using namespace std;
,並在必要時符合std::
那么一切都應該沒問題。 或者,如果您確實想要保持命名空間污染,那么請編寫限定名稱boost::geometry::distance
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.