1

ブースト( 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>'
4

1 に答える 1

5

これが、using ディレクティブを控える必要がある理由です。あなたが持っている:

using namespace std;
using namespace boost::geometry;

これらの名前空間内のすべての名前をグローバル名前空間にドラッグします。これにはstd::distanceandboost::geometry::distanceと (エラー メッセージから判断して) の両方が含まstd::distanceれ、より適切なオーバーロードとして選択されました。

を削除using namespace std;し、必要に応じて修飾すればstd::、すべて問題ありません。または、本当に名前空間の汚染を維持したい場合は、修飾名boost::geometry::distance.

于 2012-12-11T12:47:11.273 に答える