C++ cli 允许函数以另一种形式查看列表框
我的所有代码都在.cpp文件中。我在那里有一个功能: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
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.
}