struct rgb_color {
constexpr rgb_color(std::uint8_t nr, std::uint8_t ng, std::uint8_t nb) :
r(nr), g(ng), b(nb) { }
std::uint8_t r; // red
std::uint8_t g; // green
std::uint8_t b; // blue
constexpr static rgb_color black = rgb_color(0, 0, 0);
constexpr static rgb_color white = rgb_color(255, 255, 255);
};
I constexpr static
definizioni costanti sicuro per compilare:Struct è non letterale tipo
constexpr variable cannot have non-literal type 'const rgb_color'
Tuttavia secondo http://en.cppreference.com/w/cpp/concept/LiteralType, const rgb_color
dovrebbe essere un tipo letterale, perché ha solo tipi letterali come membri di dati (std::uint8_t
) e il costruttore constexpr
.
Perché il codice non viene compilato?
Inoltre, è necessario definire le constexpr static
membri in un file .cc
, come
constexpr rgb_color rgb_color::black;
Funziona se si esegue 'constexpr static rgb_color black (0, 0, 0);'? – Sean
No: http://coliru.stacked-crooked.com/a/f7915407bb464659 – tmlen
Il link che hai suggerito: "possibilmente qualificato in cv (C++ 17)". Il tuo compilatore potrebbe giocare secondo le regole del C++ 14 qui. – MSalters