Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I want to call a function from Class "A" in Class "B". Both of these classes are in the same header file.

C++
class ClassA: My own class
{
public:
  void OnMouseEvent(MouseEvent mouseEvent, CPoint point);
};

class ClassB: public CDialog
{
   void SetMinMax();
};


I've tried using:
C++
ClassB *dlg = (ClassB*) this->GetParent();

in the function "OnMouseEvent", But it gave me an:
"error C2039: 'GetParent' : is not a member of 'ClassA'

I need to call "SetMinMax() in OnMouseEvent().
Is there anyway to do it?

Thank you for helping.
Posted

Since there is no relationship between the two classes, and ClassA is not a Window class, you should put the OnMouseEvent() handler into ClassB.
 
Share this answer
 
How about this

C#
class ClassA: My own class
{
public:
  void OnMouseEvent(MouseEvent mouseEvent, CPoint point)
  {
      ClassB b;
      b.SetMinMax();
  }
};
 
class ClassB: public CDialog
{
   void SetMinMax();
};
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900