传递方法到函数c ++

时间:2013-12-28 16:49:45

标签: c++ compiler-errors c++builder-6

我正在使用Builder 6。

不知道如何修复错误:

[C++ Error] loltimer.cpp(11): E2316 '_fastcall TForm1::TForm1(TComponent *)' is not a member of 'TForm1'
[C++ Error] loltimer.cpp(18): E2062 Invalid indirection

我的.cpp代码:

// line 11
__fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner)
{
    comboSpell(ComboBox1);
}
//---------------------------------------------------------------------------

void TForm1::comboSpell(TComboBox *combo){
    // line 18
    *combo ->Items->Add("Flash");
    *combo ->Items->Add("Ignite");
    *combo ->Items->Add("Exhaust");
    *combo ->Items->Add("Teleport");
    *combo ->Items->Add("Ghost");
    *combo ->Items->Add("Heal");
    *combo ->Items->Add("Smite");
    *combo ->Items->Add("Barrier");
} 

我的.h代码:

public:     // User declarations
    __fastcall TForm1(TComponent Owner);
    void comboSpell(TComboBox *combo);

2 个答案:

答案 0 :(得分:4)

标头的参数为TComponent,而.cpp的标识为TComponent *。你需要它们是一样的。

答案 1 :(得分:2)

  

[C ++错误] loltimer.cpp(11):E2316'_fastcall TForm1 :: TForm1(TComponent *)'不是'TForm1'的成员

您的TForm()构造函数的声明在.h和.cpp代码中有所不同,特别是在Owner参数中。他们需要匹配:

public:     // User declarations
    __fastcall TForm1(TComponent *Owner);

__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
    ...
}
  

[C ++错误] loltimer.cpp(18):E2062间接无效

您使用combo运算符取消引用*指针,然后使用->运算符再次取消引用它。在这种情况下,这不起作用。你需要:

  1. 单独使用->运算符(典型用法):

    combo->Items->Add("Flash");
    
  2. 使用.运算符代替->运算符(不典型):

    (*combo).Items->Add("Flash");