分享方式:


編譯器錯誤 C2571

'function' :虛擬函式不能在聯集 'union' 中

使用虛擬函式宣告等位。 您只能在類別或結構中宣告虛擬函式。 可能的解決方案:

  1. 將等位變更為類別或結構。

  2. 讓函式成為非虛擬。

下列範例會產生 C2571:

// C2571.cpp
// compile with: /c
union A {
   virtual void func1();   // C2571
   void func2();   // OK
};