错误C2039:'Dispose':不是'System :: Windows :: Forms :: ErrorProvider'的成员

时间:2012-07-11 12:32:48

标签: winforms visual-studio-2010 visual-c++ c++-cli errorprovider

我正在尝试使用ErrorProvider Class来显示复选框上的错误。我可以使用以下代码显示错误

errorProvider1->SetError(checkBox1,"Error");

但是当我尝试使用以下代码处理此errorProvider时

errorProvider1->Dispose();

然后这一行显示错误

error C2039: 'Dispose' : is not a member of 'System::Windows::Forms::ErrorProvider'

此代码我能够在vc#中成功运行,但不能在vc ++中运行;

但是因为我的要求是在vc ++中使用它。

有人可以告诉我这段代码有什么问题。

先谢谢

1 个答案:

答案 0 :(得分:7)

根据this articleIDisposable模式在C ++ / CLI中有所不同,您无法使用该语言实现或调用Dispose()方法。

您必须使用delete运算符:

errorProvider1->SetError(checkBox1,"Error");
delete errorProvider1;  // Equivalent to errorProvider1->Dispose().