visual c ++ enum(CloseReason)

时间:2009-09-21 14:06:26

标签: visual-c++ enums

当我写下以下内容时:

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 个答案:

答案 0 :(得分: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;
  }
}

不知道为什么你需要完全限定它,但它允许它编译。<​​/ p>