2009-09-21 43 views
-1

當我寫:的Visual C++枚舉(CloseReason)

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

我得到這個錯誤:

###\queue.h(153) : error C2039: 'FormOwnerClosing' : is not a member of 'System::Windows::Forms::Form::CloseReason' 1>###\queue.h(24) : see declaration of 'System::Windows::Forms::Form::CloseReason' 1>###\queue.h(153) : error C2065: 'FormOwnerClosing' : undeclared identifier

我不明白這是爲什麼。任何人都可以幫忙嗎?

+0

你究竟想要做什麼?你得到的錯誤是什麼? – Glen 2009-09-21 14:08:40

+0

它在我看來,你是enum類型(CloseReason)與enum的實例(e-> CloseReason)混淆。 – 2009-09-21 14:11:18

+0

queue_FormClosing if(e-> CloseReason!= CloseReason :: FormOwnerClosing)e-> Cancel = true; 錯誤C2065:'FormOwnerClosing':未聲明的標識符 – n00b 2009-09-21 14:11:20

回答

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; 
    } 
} 

不知道爲什麼你需要完全限定它,但它允許它來編譯。

+0

thx :) 那就是爲什麼我討厭ms; D – n00b 2009-09-21 14:46:59

+3

@ n00b32 - 你討厭微軟,因爲你沒有足夠的技能來使用他們的產品?很奇怪...... – 2009-09-21 14:50:46

+0

@greg它不是關於技巧:)它關於運行他們的產品的奇怪的不合邏輯的規則 – n00b 2009-09-21 15:00:03