【问题标题】:Embarcadero C++ Builder - Public Function [duplicate]Embarcadero C++ Builder-公共功能[重复]
【发布时间】:2014-07-13 22:32:43
【问题描述】:

我有两个表格(form_1 和 form_2)。 我在 form_1 的主体中创建了一个函数。

void ExampleFunction() {
    ShowMessage("I'm example function inside form_1");
}

我想从 form_2 中调用它。

我尝试将此函数添加到form_1的头文件中。

public: // User declarations
    __fastcall Tform_2(TComponent* Owner);
    void ExampleFunction();
};

但是当我想从 form_2 中调用它时,例如:

form_2->ExampleFunction();

Builder 给我一个错误:“[ilink32 Error] Error: Unresolved external”

那么我怎样才能正确地让它工作呢?

【问题讨论】:

  • 在那个“骗局”中经历了很多案例......对于初学者来说可能非常可怕

标签: c++ function c++builder public


【解决方案1】:

你在自相矛盾。您说要在 Form_1 中实现函数并从 Form_2 调用它,但您试图在 Form_2 中实现它并从 Form_2 外部调用它。

在任何情况下,您都将函数声明为 Tform_2 类的成员,因此您需要这样限定函数的主体:

void Tform_2::ExampleFunction() {
    ShowMessage("I'm example function inside form_1");
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-10
    相关资源
    最近更新 更多