-3

i have two classes A & B.i want to call a member function of A by member function of B.

class A {
   public:
      void memberofa();
}

class b:

 class B {
  public:
    void memberofb();
}

now i need to call memberofa from inside memberofb. Any suggestions and syntaxes will be helpful

Hemanth
  • 1
  • 1
  • 1
  • 4

2 Answers2

0

Something like this?

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 A\n");
      };
};

class B {
   public:
      B() {};
      void memberofb()
      {
        printf("printing from member of B\n");
        A objA;
        objA.memberofa();
      };
};

int main()
{
    A a;
    B b;

    b.memberofb();
    return 0;
}
Rorschach
  • 734
  • 2
  • 7
  • 22
0
  1. B inherit from A
  2. B contain A object
  3. A::memberofa is static function
  4. A is singleton class
  5. A inherit from B, B has memberofa and it is virtual function.
  • 1
    Expanding this answer into a full (albeit pseudo-) code example would really help readability! – Tobbe Oct 28 '15 at 11:38