.net 为什么DialogResult::Yes需要一个::?
为什么这样做有效:.net 为什么DialogResult::Yes需要一个::?,.net,namespaces,c++-cli,messagebox,.net,Namespaces,C++ Cli,Messagebox,为什么这样做有效: using namespace System; using namespace System::Windows::Forms; ... if( MessageBox::Show("Really do it?", "Are you sure?", System::Windows::Forms::MessageBoxButtons::YesNo) == System::Windows::Forms::DialogResult::Yes ) { Console::Write
using namespace System;
using namespace System::Windows::Forms;
...
if( MessageBox::Show("Really do it?", "Are you sure?", System::Windows::Forms::MessageBoxButtons::YesNo) == System::Windows::Forms::DialogResult::Yes )
{
Console::WriteLine("Do it!");
}
…如果失败:
using namespace System;
using namespace System::Windows::Forms;
...
if( MessageBox::Show("Really do it?", "Are you sure?", System::Windows::Forms::MessageBoxButtons::YesNo) == DialogResult::Yes )
{
Console::WriteLine("Do it!");
}
…出现以下错误:
error C2039: 'Yes' : is not a member of 'System::Windows::Forms::Form::DialogResult'
我假设Visual Studio正在拾取DialogResult,但我看不到它在哪里找到它?这是命名冲突,Form.DialogResult是Form的属性。我假设您的代码是表单的一部分,因此具有优先权。
System::Windows::Forms::DialogResult
),因此出现错误
我确信答案是显而易见的,但我看不到它…
系统::Windows::窗体::窗体::DialogResult
(在错误消息中)?这很奇怪。我应该提到,上面的代码片段是从一个派生自System::Windows::Forms::Form
…的类调用的,我认为这实际上回答了这个问题-大概System::Windows::Forms::Form
有一个Dialog::Result
方法或属性,因此它发现标准windows窗体版本?我就是这么想的,是的。如果这是真的,那么编译器或C++-CLI是相当愚蠢的。普通C++要求在查找<>代码>之前:只找到类型和名称空间::< /Cord>。在上面的评论中,他确实提到了他是从::Forms::Form派生出来的,这似乎是MS在这个问题上的失误。