C++ c++;调用类';另一类的s函数';s函数

C++ c++;调用类';另一类的s函数';s函数,c++,class,function,pointers,C++,Class,Function,Pointers,我希望这对你有意义,我感到困惑。如果有更简单的方法,请告诉我: double A::a(double(b::*bb)()) { b.init(); return (b->*bb)(); } void A::run(); { cout<< a(b.b1); cout<< a(b.b2); } class A { B b; void run(); double a(double(b::*bb)()); }; class B { vo

我希望这对你有意义,我感到困惑。如果有更简单的方法,请告诉我:

double A::a(double(b::*bb)())
{
  b.init();
  return (b->*bb)();
}

void A::run();
{
  cout<< a(b.b1);
  cout<< a(b.b2);
}

class A
{
  B b;
  void run();
  double a(double(b::*bb)());
};

class B
{
  void init();
  double b1();
  double b2();
};
double A::A(double(b::*bb)()
{
b、 init();
返回(b->*bb)();
}
void A::run();
{
不能这是:

应该是:

double a(double(B::*bb)());

也就是说,
bb
将被声明为类
B
中成员函数的指针,而不是对象
B
(它是一个实例,本身不是类型,因此不能是类型的一部分)。

它没有意义。尽管如此:

class B // <- class B definition comes first
{
  void init();
  double b1();
  double b2();
};

class A
{
  B b;
  void run();
  double a(double(B::*bb)()); // <- B instead of b
};

double A::a(double(B::*bb)()) // <- B instead of b
{
  b.init();
  return (b->*bb)();
}

void A::run() // <- you can't put semicolon here
{
  cout<< a(&B::b1); // <- you want to pass the address of a member.
  cout<< a(&B::b2); // <- you want to pass the address of a member.
}

<代码>类B//你的问题到底是什么?这是没有意义的。什么是代码> BB<代码>?你是否收到错误消息?你能发布吗?你实际上是通过这样做来实现的?BTW,<代码> B::init < /C> >应该是代码> B::B/<代码>;C++有真正的构造函数。
class B // <- class B definition comes first
{
  void init();
  double b1();
  double b2();
};

class A
{
  B b;
  void run();
  double a(double(B::*bb)()); // <- B instead of b
};

double A::a(double(B::*bb)()) // <- B instead of b
{
  b.init();
  return (b->*bb)();
}

void A::run() // <- you can't put semicolon here
{
  cout<< a(&B::b1); // <- you want to pass the address of a member.
  cout<< a(&B::b2); // <- you want to pass the address of a member.
}