Enum doesn't have an unnamed constructorDRT-W1658
The analyzer produces this diagnostic when the constructor invoked to initialize an enum constant doesn't exist.
Examples
The following code produces this diagnostic because the enum constant c
is being initialized by the unnamed constructor, but there's no unnamed
constructor defined in E
:
enum E {
c();
const E.x();
}
The following code produces this diagnostic because the enum constant c
is being initialized by the constructor named x
, but there's no
constructor named x
defined in E
:
enum E {
c.x();
const E.y();
}
Common fixes
If the enum constant is being initialized by the unnamed constructor and one of the named constructors should have been used, then add the name of the constructor:
enum E {
c.x();
const E.x();
}
If the enum constant is being initialized by the unnamed constructor and none of the named constructors are appropriate, then define the unnamed constructor:
enum E {
c();
const E();
}
If the enum constant is being initialized by a named constructor and one of the existing constructors should have been used, then change the name of the constructor being invoked (or remove it if the unnamed constructor should be used):
enum E {
c.y();
const E();
const E.y();
}
If the enum constant is being initialized by a named constructor and none of the existing constructors should have been used, then define a constructor with the name that was used:
enum E {
c.x();
const E.x();
}