0

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

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

friend class detailedForm;

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

表格.h

...
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;
        }
}

详细表格.h

public:
...
    void DisplayLabel(void);

detailForm.cpp 的代码

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

2 回答 2

0

它看起来像是displayInfo的成员函数CharFormDetail。这意味着您必须使用ChartFormDetail.

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

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

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

于 2011-12-14T08:46:36.997 回答
0

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

如果您正在寻找一个示例来了解如何使用友元函数,您可以查看: http: //www.learncpp.com/cpp-tutorial/813-friend-functions-and-classes/

于 2011-12-14T07:12:48.737 回答