C++ cli 允许函数以另一种形式查看列表框

C++ cli 允许函数以另一种形式查看列表框,c++-cli,C++ Cli,我的所有代码都在.cpp文件中。我在那里有一个功能: void funct1 (void) { ... if (num_fields) { for (ix = 0; ix < num_fields; ix++) if (status == OK) checkedListBox1->Items->Add(gcnew String(buffer)); } else

我的所有代码都在.cpp文件中。我在那里有一个功能:

void funct1 (void)    
{
    ...
    if (num_fields) {
        for (ix = 0; ix < num_fields; ix++)
            if (status == OK)
                checkedListBox1->Items->Add(gcnew String(buffer));
    } else
        checkedListBox1->Items->Add("No available extra data fields");
}
如果
functl()
不是类的一部分,则需要将
checkedListBox1
作为参数传入,如下所示:

void funct1(System::Windows::Forms::CheckedListBox% checkedListBox1)
{
    ...
}
而不是在调用函数中:

System::Void Form5::MainMAFBrowseBtn_Click(System::Object^  sender, System::EventArgs^  e)
{
    ...
    functl(checkedListBox1);
}
或者在类
Form5
中,可以将
functl
的声明放在那里:

class Form5
{
    ...
private:
    void functl();
};
然后在
.cpp
文件中,只需将
functl
声明为:

void Form5::functl()
{
    /// Now you have direct access to checkedListBox1.
}

如果
func1(void)
是类的一部分,则必须将类名放在函数名之前(例如,如果类名为
Form5
,则函数定义必须类似于.cpp文件中的
void Form5::funct1(void)
请显示
checkedListBox1的声明
对不起,我不确定您的意思,我的表格中有这个。h:this->checkedListBox1=(gcnew System::Windows::Forms::CheckedListBox());和:public:System::Windows::Forms::CheckedListBox^checkedListBox1;基本OOP,在使用Form5^对象的任何成员之前,需要对其进行引用。
void Form5::functl()
{
    /// Now you have direct access to checkedListBox1.
}