繁体   English   中英

如何使用C ++好友函数在Bada中调用函数/将值从一个类传递到另一个类

[英]How to call function/pass value from one class to another in bada using C++ friend function

我知道这是一个基本的c ++问题,但是我是否可以知道如何使用好友函数在bada中从一个类向另一个类调用函数/传递值(elementId)?

在我的表单类中,我有一个listView,当单击listView中的项目时,我想将elementId传递给detailForm以在标签中显示信息(在detailForm中)。 在我的form.h和.cpp文件中,我包含了detailForm.h,我是否知道如何访问detailForm中的函数以显示信息? 在form.h中,我还声明了

friend class detailedForm;

当我尝试在表单类中的detailForm中使用其中一个函数时,即displayInfo(); 表单类有一个错误,表明未声明displayInfo()。

形式

...
public:
    friend class ChartFormDetail;

这是我的form.cpp代码

#include "Form.h"
#include "ChartFormDetail.h"
...

void
Form::OnGroupedListViewItemStateChanged(Osp::Ui::Controls::GroupedListView &listView, int groupIndex, int itemIndex, int elementId, Osp::Ui::Controls::ListItemStatus state)
{
    Frame* pFrame = Osp::App::Application::GetInstance()->GetAppFrame()->GetFrame();
    FormMgr* pFormMgr = dynamic_cast<FormMgr*> (pFrame->GetControl("FormMgr"));

    if(pFormMgr == null)
    return;

    pFormMgr->SendUserEvent(FormMgr::REQUEST_DETAILFORM, null);
    //pFormMgr->SendUserEvent(elementId, null);


    switch(elementId)
        {
        case ID_FORMAT_STRING_M12:
            DisplayLabel();
            break;
...
        case ID_FORMAT_STRING_F19:
            DisplayLabel();
            break;
        }
}

detailForm.h

public:
...
    void DisplayLabel(void);

detailForm.cpp的代码

void
ChartFormDetail::DisplayInfo(void)
{
    pLabel->SetText("Text here");
    RequestRedraw();
}

您如何尝试在类中调用displayInfo()? 您需要一个“ detailedForm”对象来访问它。 另外,如果需要访问朋友类(detailedForm)中的listView数据,则需要引用listView对象。

如果您正在寻找一个示例来了解如何使用好友功能,则可以查看以下网址http : //www.learncpp.com/cpp-tutorial/813-friend-functions-and-classes/

看起来displayInfoCharFormDetail的成员函数。 这意味着您必须使用ChartFormDetail实例来调用它。

要使其正常工作,您需要执行以下操作:

ChartFormDetail & details = getDetails();
details.displayInfo();

这只是一个例子。 我不知道如何获得ChartFormDetails实例,这在很大程度上取决于您的体系结构。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM