我試圖通過使用libkdtree ++,試圖實現RRT,雖然我找到了一些麻煩了解如何使用這個庫的工作我的方式。繼examples,我嘗試定義我的RRT類的輪廓爲這樣:的std :: ptr_fun參數困難模板類和結構
#pragma once
#include "coupling_tree.h"
#include "kdtree++/kdtree.hpp"
#include <deque>
#include <iostream>
#include <vector>
#include <limits>
#include <functional>
#include <set>
namespace trajectory {
template<int c_dim> struct Point {
std::set<const void*> registered;
Eigen::VectorXd p;
Point(Eigen::VectorXd point) :
p(point)
{
assert(point.size() == c_dim);
}
~Point()
{
bool unreg_ok = (registered.find(this) != registered.end());
assert(unreg_ok);
registered.erase(this);
}
double distance_to(Point const & x) const
{
double dist = 0;
for (int i = 0; i < c_dim; ++i)
dist += (p[i] - x[i])*(p[i] - x[i]);
return std::sqrt(dist);
}
inline double operator[](size_t const N) const { return p(N); }
};
template<int c_dim> double tac(Point<c_dim> p, size_t k) { return p[k]; }
template<int plant_dim, int c_dim>
class RRT { //TODO: Should this be abstract so we can quickly implement lots of RRT variants?
///////TYPEDEFS
typedef Point<c_dim> point;
typedef KDTree::KDTree<c_dim, point, std::pointer_to_binary_function<point, size_t, double> > kd_tree;
////////////VARIABLES
private:
kd_tree tree;
////////////////////
public:
protected:
private:
const int getNumDim() const {
return plant_dim;
}
};
}
我們得到以下錯誤:
Severity Code Description Project File Line Suppression State
Error C2664 'std::pointer_to_unary_function<trajectory::Point<5>,std::size_t,size_t (__cdecl *)(trajectory::Point<5>)> std::ptr_fun<trajectory::Point<5>,std::size_t>(_Result (__cdecl *)(_Arg))': cannot convert argument 1 from 'double (__cdecl *)(trajectory::Point<c_dim>,std::size_t)' to 'size_t (__cdecl *)(trajectory::Point<5>)' test_RRT C:\ResearchCode\robot-new\robot\projects\RRT\include\RRT.h 83
Error C2512 'std::pointer_to_binary_function<trajectory::Point<5>,std::size_t,double,_Result (__cdecl *)(_Arg1,std::_Arg2)>': no appropriate default constructor available test_RRT C:\ResearchCode\robot-new\robot\externals\libkdtree\kdtree++\kdtree.hpp 126
我在打字變得非常失去了在這裏和什麼特別是抱怨,特別是因爲我是以這種方式使用ptr_fun的新手。有人可以解釋錯誤,並修復?
運營商[]在點有模板,而類點已經有模板 .... –
JHBonarius
好抓,但這並沒有改變這個問題。我將編輯代碼。謝謝! – user650261