通过另一类的成员函数调用一个类的成员功能

calling a member function of a class by member function of another class?

本文关键字:成员 一个 功能 函数调用 一类      更新时间:2023-10-16

我有两个类A&B.我想通过B.的成员函数调用a的成员函数。

class A {
   public:
      void memberofa();
}

b类:

 class B {
  public:
    void memberofb();
}

现在我需要从memberofb内部调用memberofa。任何建议和语法都将有助于

类似的东西?

class A {
   public:
      A() {};
      void memberofa()
      {
        //you cant make object of B here because compiler doesn't see B yet
        //if you do want to make Object of B here, define this function somewhere
        //after definition of B class
        printf("printing from member of An");
      };
};
class B {
   public:
      B() {};
      void memberofb()
      {
        printf("printing from member of Bn");
        A objA;
        objA.memberofa();
      };
};
int main()
{
    A a;
    B b;
    b.memberofb();
    return 0;
}
  1. B继承自A
  2. B包含A对象
  3. A: :memberofa是静态函数
  4. A是singleton类
  5. A继承自B,B具有memberofa,它是虚函数
相关文章: