从类"A"调用函数在"B"类中 [英] call function from class "A" in class "B"

查看:66
本文介绍了从类"A"调用函数在"B"类中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想从"B"类的"A"类中调用一个函数.这两个类都在同一个头文件中.

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();


在功能"OnMouseEvent"中,但它给了我一个:
错误C2039:" GetParent:不是'ClassA'的成员

我需要在OnMouseEvent()中调用"SetMinMax()".
反正有做吗?

感谢您的帮助.


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.

推荐答案

由于两个类之间没有关系,并且ClassA不是Window类,因此应放置OnMouseEvent()处理程序进入ClassB.
Since there is no relationship between the two classes, and ClassA is not a Window class, you should put the OnMouseEvent() handler into ClassB.


如何处理

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();
};


这篇关于从类"A"调用函数在"B"类中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆