Calling a member function of another class from another class

I have two classes A and B. The control is inside one of the member functions of class A. The member function calculates the result, and now I want to send this value to one of the member functions of class B, I tried as follows, but it doesn’t works

int memberFunctionOfA ()
{
... // results are stored in some temporary value, say temp

B :: memberFunctionOfB (temp); // the way i tried
}

The compiler reported an error. I also tried how

B obj;
obj.memberFunctionOfB (temp);

Both gave me errors that cannot be caused by memberFunctionOfB. Can someone tell me what I am missing

Edit

Class B is not inherited from A. Both are independent. Both member functions are public and non-static.

+3
2

:

int memberFunctionOfA()
{
... //results are stored in some temporary value, say temp

    B obj;
    obj.memberFunctionOfB(temp);
}

..., . B, . B , , - B :

class B
{
public:
  void memberFunctionOfB(const TypeOfTemp &temp);
};

// Later in class A definition
class A
{
public:
  int memberFunctionOfA()
  {
    ... //results are stored in some temporary value, say temp

    B b;
    b.memberFunctionOfB(temp);
  }
};

- B , :

class B
{
public:
  static void memberFunctionOfB(const TypeOfTemp &temp);
};

...

class A
{
public:
  int memberFunctionOfA()
  {
    ... //results are stored in some temporary value, say temp

    B::memberFunctionOfB(temp);
  }
};
+3

:

" B:: B()"

, B . B .

, , .

+1

Source: https://habr.com/ru/post/1791872/


All Articles