小编Mat*_*tia的帖子

c ++指向非静态成员函数的指针

我已经阅读了很多关于非静态成员函数指针的帖子和答案,但没有人能够解决我的问题.
所以我在这里创建了一个简短的例子来复制我的问题:即使这个例子可以以不同的方式"解决",对于最终的软件,保持结构就像在例子中一样重要,谢谢.

这是"Funcs.h"类的标题:

class Funcs
{
private:
  double a = 1, b = 2;

public:
  Funcs();
  ~Funcs();
  double Fun1(double X);
  double solver(double X0);
  double aaa(double(*fun)(double), double x0);
};
Run Code Online (Sandbox Code Playgroud)

这是"Funcs.cpp"类的cpp:

#include "Funcs.h"

using namespace std;

Funcs::Funcs()
{
}

Funcs::~Funcs()
{
}

double Funcs::Fun1(double X) {
  double f1 = a*X;

  return f1;
}

double Funcs::solver(double X0)
{
  double result;

  result = aaa(Fun1, X0);
  return result;
}

double Funcs::aaa(double(*fun)(double), double x0)
{
  return fun(x0);
}
Run Code Online (Sandbox Code Playgroud)

最后这是主要的"main.cpp":

#include <iostream>
#include "Funcs.h"

using namespace std; …
Run Code Online (Sandbox Code Playgroud)

c++ function-pointers non-static

7
推荐指数
1
解决办法
3000
查看次数

标签 统计

c++ ×1

function-pointers ×1

non-static ×1