Share via


編譯器錯誤 C2571

'function' : 虛擬函式不可以在等位 'union' 中

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

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

  2. 使函式成為非虛擬。

下列範例會產生 C2571:

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