Anteckning
Åtkomst till den här sidan kräver auktorisering. Du kan prova att logga in eller ändra kataloger.
Åtkomst till den här sidan kräver auktorisering. Du kan prova att ändra kataloger.
operator 'operator-name': deprecated between enumerations and floating-point types
Remarks
C++20 has deprecated the usual arithmetic conversions on operands, where one operand is of enumeration type and the other is of floating-point type. For more information, see C++ Standard proposal P1120R0.
In Visual Studio 2019 version 16.2 and later, an implicit conversion between enumeration types and floating-point types produces a level 1 warning when the /std:c++latest compiler option is enabled. In Visual Studio 2019 version 16.11 and later, it also produces a warning under /std:c++20.
Example
In Visual Studio 2019 version 16.2 and later, a binary operation between an enumeration and a floating-point type produces a level 1 warning when the /std:c++latest compiler option is enabled. In Visual Studio 2019 version 16.11 and later, it also produces a warning under /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
}
To avoid the warning, use static_cast to convert the second operand:
// 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;
}