我有很多的方法,这是从std::unary_function<K::Point_3, K::FT>
加typedef K::Point_3 Point;
导出(底层库CGAL要求的话) - 这个班级被称为Function
。
我现在需要一些派生类(例如:MySphere
)的实例添加到Function_vector
:
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Implicit_to_labeling_function_wrapper.h>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef K::FT FT;
class Function: public std::unary_function<K::Point_3, K::FT>
{
public:
typedef K::Point_3 Point; // necessary
// I'd rather not define operator() here
virtual K::FT operator()(K::Point_3 p) const {return 0.0;}
};
class MySphere: public Function
{
public:
virtual K::FT operator()(K::Point_3 p) const {return 3.14;}
};
typedef CGAL::Implicit_multi_domain_to_labeling_function_wrapper<Function>
Function_wrapper;
typedef Function_wrapper::Function_vector Function_vector;
int main()
{
MySphere f1;
Function_vector v;
v.push_back(f1);
std::cout << f1(CGAL::ORIGIN) << std::endl; // MySphere::operator()
std::cout << v[0](CGAL::ORIGIN) << std::endl; // Function::operator() :(
return 0;
}
问题:
Function_vector
不接受指针,所以实际的抽象Function
类不能是虚拟的,需要从std::unary_function
执行operator()
。当将MySphere
实例添加到Function_vector
时,MySphere
变为Function
而Function
的operator()
被调用,而不是MySphere
。
如何拥有v[0]
致电MySphere::operator()
?
谢谢,这是我的想法。我会回到CGAL开发者。 –