共用方式為


編譯器警告 (層級 1) C5055

運算子 ' operator-name ':列舉和浮點類型之間已被取代

備註

C++20 已取代運算元上的一般算術轉換,其中一個運算元是列舉型別,另一個是浮點類型。 如需詳細資訊,請參閱 C++ 標準提案 P1120R0

在 Visual Studio 2019 16.2 版和更新版本中,列舉類型和浮點類型之間的隱含轉換會在啟用編譯器選項時 /std:c++latest 產生層級 1 警告。 在 Visual Studio 2019 16.11 版和更新版本中,它也會在 下 /std:c++20 產生警告。

範例

在 Visual Studio 2019 16.2 版和更新版本中,列舉與浮點類型之間的二進位作業會在啟用編譯器選項時 /std:c++latest 產生層級 1 警告。 在 Visual Studio 2019 16.11 版和更新版本中,它也會在 底下 /std:c++20 產生警告:

// C5055.cpp
// Compile using: cl /EHsc /W4 /std:c++latest C5055.cpp
enum E1 { a };
int main() {
  double i = a * 1.1; // Warning C5055: operator '*': deprecated between enumerations and floating-point types
}

若要避免警告,請使用 static_cast 來轉換第二個運算元:

// C5055_fixed.cpp
// Compile using: cl /EHsc /W4 /std:c++latest C5055_fixed.cpp
enum E1 { a };
int main() {
   double i = static_cast<int>(a) * 1.1;
}