Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++/MFC
Hi,
 
I want to call a function from Class "A" in Class "B". Both of these classes are in the same header file.
 
class ClassA: My own class
{
public:
  void OnMouseEvent(MouseEvent mouseEvent, CPoint point);
};
 
class ClassB: public CDialog
{
   void SetMinMax();
};
 
I've tried using:
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 6-Mar-12 19:25pm
skfoo1691
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Since there is no relationship between the two classes, and ClassA is not a Window class, you should put the OnMouseEvent() handler into ClassB.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

How about this
 
class ClassA: My own class
{
public:
  void OnMouseEvent(MouseEvent mouseEvent, CPoint point)
  {
      ClassB b;
      b.SetMinMax();
  }
};
 
class ClassB: public CDialog
{
   void SetMinMax();
};
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 410
1 Jochen Arndt 200
2 Richard MacCutchan 135
3 DamithSL 105
4 PIEBALDconsult 90
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,032
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,220


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 7 Mar 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100