Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 为什么DialogResult::Yes需要一个::?_.net_Namespaces_C++ Cli_Messagebox - Fatal编程技术网

.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的属性。我假设您的代码是表单的一部分,因此具有优先权。

有一个属性,也称为DialogResult(类型为
System::Windows::Forms::DialogResult
),因此出现错误


我确信答案是显而易见的,但我看不到它…
系统::Windows::窗体::窗体::DialogResult
(在错误消息中)?这很奇怪。我应该提到,上面的代码片段是从一个派生自
System::Windows::Forms::Form
…的类调用的,我认为这实际上回答了这个问题-大概
System::Windows::Forms::Form
有一个
Dialog::Result
方法或属性,因此它发现标准windows窗体版本?我就是这么想的,是的。如果这是真的,那么编译器或C++-CLI是相当愚蠢的。普通C++要求在查找<>代码>之前:只找到类型和名称空间::< /Cord>。在上面的评论中,他确实提到了他是从::Forms::Form派生出来的,这似乎是MS在这个问题上的失误。