首页 文章

visual c enum(CloseReason)

提问于
浏览
-1

当我写下面的内容时:

private: System::Void queue_FormClosing(
    System::Object^ sender, 
    System::Windows::Forms::FormClosingEventArgs^ e) {
    if(e->CloseReason!=CloseReason::FormOwnerClosing) e->Cancel=true;
}

我收到此错误:

\ queue.h(153):错误C2039:'FormOwnerClosing':不是'System :: Windows :: Forms :: Form :: CloseReason'1> ### \ queue.h(24)的成员):参见'System :: Windows :: Forms :: Form :: CloseReason'1> ### \ queue.h(153)的声明:错误C2065:'FormOwnerClosing':未声明的标识符

我不明白为什么会这样 . 有人可以帮忙吗?

1 回答

  • 2

    出于某种原因,您需要将枚举完全限定为System :: Windows :: Forms :: CloseReason :: FormOwnerClosing .

    不编译:

    private: System::Void Form1_FormClosing(System::Object^  sender,
                     System::Windows::Forms::FormClosingEventArgs^  e) {
      if (e->CloseReason == CloseReason::FormOwnerClosing) {
        e->Cancel = true;
      }
    }
    

    编译:

    private: System::Void Form1_FormClosing(System::Object^  sender,
                     System::Windows::Forms::FormClosingEventArgs^  e) {
      if (e->CloseReason == System::Windows::Forms::CloseReason::FormOwnerClosing) {
        e->Cancel = true;
      }
    }
    

    不知道为什么你需要完全限定它,但它允许它编译 .

相关问题