Wpis z mikrobloga

#programowanie #cpp mam sobie enum class jakiś i wartość po cascie na int jest zapisywana do bazy danych. Czy mam pewność, że te wartości zawsze będą takie same, po kolei? Bez względu na to, że np. skompilowałem program po zmianach i np. po roku, to wczytując z tej bazy danych tego inta i castując na enuma będzie to samo? Czy jednak muszę pisać = 0, = 1, = 2 itd?
  • 4
  • Odpowiedz
@Dijuna: http://en.cppreference.com/w/cpp/language/enum

When initializers are provided in the enumerator-list, the values of enumerators are defined by those initializers. If the first enumerator does not have an initializer, the associated value is zero. For any other enumerator whose definition does not have an initializer, the associated value is the value of the previous enumerator plus one.

Te wartości są dobrze zdefiniowane i się nie zmienią.
  • Odpowiedz