C++ 如何在一个类中调用另一个类中的函数对象?

C++ 如何在一个类中调用另一个类中的函数对象?,c++,function,class,oop,C++,Function,Class,Oop,我在类adilog中有一个函数,它有一个用户输入x11,我想在类BDoc中调用它。怎么做 .h file #ifndef A_DIALOG_H #define A_DIALOG_H class ADialog : public wxDialog { public: ADialog(wxWindow* parent, wxWindowID id, int click); wxTextCtrl *d_x1; void setAData(); }; #endi

我在类
adilog
中有一个函数,它有一个用户输入
x11
,我想在类
BDoc
中调用它。怎么做

.h file
#ifndef A_DIALOG_H
#define A_DIALOG_H

class ADialog : public wxDialog
{
public:
      ADialog(wxWindow* parent, wxWindowID id, int click);
      wxTextCtrl *d_x1;
      void setAData();  
};
#endif
.cpp文件的一部分

void ADialog::setAData()
{
    double x11; 
    d_x1->GetValue().ToDouble(&x11);    
}
void BDoc::ATCut()
{
    //(get the value of x11 that user inputs in this part)
}
.cpp文件的一部分

void ADialog::setAData()
{
    double x11; 
    d_x1->GetValue().ToDouble(&x11);    
}
void BDoc::ATCut()
{
    //(get the value of x11 that user inputs in this part)
}

让我们班成为BDoc班的朋友。因此,您可以轻松访问类BDoc中的类adilog函数。

在调用者类中包含
adilog
类头
BDoc
,然后调用
SetAData()


如果需要,可以修改
SetAData()
以返回
x11

我在
adilog
中没有看到任何方法。SetAData()不是成员函数吗?在类声明中没有这样声明。我不知道它是
公共的
还是
私人的
。它是静态的还是非静态的?你能发布完整的类吗?哦,好的,对不起,它是公共的,我会编辑它,因为它不是
静态的
,你需要
BDoc
中的
adilog
的一个实例来获取该方法的结果。我这样做了,但是x11没有被访问,我无法更改类型,它是无效的。我的意思是改变类型意味着改变更多的东西,所以我想知道是否还有其他方法round@Leo001将
x11
作为成员变量,并通过公共接口访问它怎么样?@Leo001您可以通过
d_x1
直接在
BDoc
中获取
x11
吗?非常感谢,我刚刚找到了一种方法在另一个类中声明指针,然后在adilog::setAData aswxGetApp().getPattern()->xc1中调用它=x11@Leo001因此,朋友的缺失并不是罪魁祸首。忘掉这个“答案”。