在坐标类型和使用增强几何库模板化我的类时出现编译错误
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);
的免费函数可以避免这个问题。
我同意 us2012 的答案,建议使用 boost::geometry::get<0>()。
实际问题是缺少模板关键字,因此:
{ return p.template get<0>(); }
会解决问题。
相关文章:
- C++:处理错误,看不懂我的错误
- 我用C++做了一个计算器,但我对"type of calculator"的要求循环了两次。有人可以帮助指出我的错误吗?
- 我不明白我的错误需要返回一个指针数组
- 我在 c++ 中的 AES 代码有问题。明文正在更改,但加密邮件是相同的。我找不到我的错误
- 这是 Clang 的错误还是我的错误?
- [堆栈][列表]我无法理解我的错误
- 检查我的 C++ 代码!我的cmd屏幕在运行后关闭!我的错误可能是什么
- 在C 中继承类功能:一般问题,以更好地理解,如果有人可以指出我的错误
- 我正在尝试学习使用 SDL 制作游戏。我的书教SDL1.2.3,我无法让它在Visual Studio上工作。谁能帮忙?我的错误:
- 马洛克或我的错误
- 我正在尝试遍历 20x20 网格并计算产品,但总是得到不正确的结果。你能帮忙发现我的错误吗?
- C++自动问题还是我的错误?
- 这是标准库错误,还是我的错误
- while 循环的两个条件。我的错误是什么?
- 我的错误,还是英特尔编译器的错误?非静态成员错误的大小
- 将每个单词的第一个字符大写-帮助查找我的错误
- 是什么导致了我的错误?我试图创建一个球员类和存储球员的名字作为一个变量
- 如何解决我的错误LNK2019
- 找不到我的错误!错误:"("标记之前的预期标识符
- 找不到我的错误 - 抽象错误