3

access という名前の constexpr 関数があり、配列から 1 つの要素にアクセスしたい:

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

エラーが発生します:

error: the value of 'al' is not usable in a constant expression

access から要素の 1 つにアクセスできないのはなぜですか? または、可能であればどうすればよいですか?

4

1 に答える 1