簡體   English   中英

在坐標類型上模擬我的類並使用Boost Geometry庫時出現編譯錯誤

[英]Compilation error when templating my class on coordinate type and using Boost Geometry library

我正在Boost Geometry庫上編寫庫代碼。 我的類應該在坐標類型上進行模板化(通常是int / float / double等)。 下面的代碼(剝離到最低限度)不編譯,我得到一個對我沒有幫助的編譯錯誤。

編碼:

#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point.hpp>

template <typename CoordType>
class MyClass {
public:
    typedef boost::geometry::model::point<CoordType, 2, boost::geometry::cs::cartesian> MyPoint;
    CoordType getX(const MyClass<CoordType>::MyPoint &p) const { return p.get<0>(); }
};

錯誤:

test.cpp: In member function 'CoordType MyClass<CoordType>::getX(const MyClass<CoordType>::MyPoint&) const':
test.cpp:8:82: error: expected primary-expression before ')' token

我正在使用以下代碼編譯此代碼: g++ -I./boost_1_54_0 test.cpp -o test.o 我使用了不同版本的G ++ 4.5.2 / 4.7.2 / 4.8.1,但我仍然得到同樣的錯誤。

我在這里錯過了什么? 提前致謝。

使用自由函數boost::geometry::get<0>(p); 在boost文檔中推薦可以避免這個問題。

我同意us2012的答案,建議使用boost :: geometry :: get <0>()。

實際問題是缺少模板關鍵字,因此:

{return p。 template get <0>(); }

會解決這個問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM