也许我是用这个问题离开左边的领域,但是有可能通过构造函数定义成员函数吗? 在我的情况下,我想写一个类来执行健壮的模型拟合(使用RANSAC)。我希望这可以推广到不同类型的模型。例如,我可以用它来确定飞机对一组3D点的估计。或者,也许我可以确定两组点之间的转换。在这两个例子中,可能需要有不同的错误函数和不同的拟合函数。而不是使用类,静态函数调用可能看起来像 model = estimate(data
struct A
{
void f() {}
};
void f() {}
int main()
{
auto p1 = &f; // ok
auto p2 = f; // ok
auto p3 = &A::f; // ok
//
// error : call to non-static member functio
我有一个Collection类,它旨在存储不同类型的对象,但是我想调用这些类共享的特定方法名称(例如ToString())。 这里是我的尝试: class Collection {
public:
void *data[];
void Collection() {}
void ~Collection() {
for (int i = 0; i
struct test
{
void f() {};
};
test t1;
using memfun_t = void (test::*)();
memfun_t mf = &test::f;
auto a1 = &test::f; // OK
auto a2 = t1.*mf; // error
auto a3 = &(t1.*mf); // still no