Warum ist ein const-Array von einer constexpr-Funktion aus nicht zugänglich?
Ich habe eine Constexpr-Funktion namens access, und ich möchte ein Element aus einem Array zugreifen:
char const*const foo="foo";
char const*const bar[10]={"bar"};
constexpr int access(char const* c) { return (foo == c); } // this is working
constexpr int access(char const* c) { return (bar[0] == c); } // this isn't
int access(char const* c) { return (bar[0] == c); } // this is also working
Ich bekomme den Fehler:
error: the value of 'al' is not usable in a constant expression
Warum kann ich nicht über den Zugriff auf eines der Elemente zugreifen? oder besser wie mache ich das, wenn es überhaupt möglich ist?