1

This little piece of code drives me a bit crazy:

struct my_struct
{
private:
    static constexpr const char* some_string() noexcept;
public:
    my_struct() = default;
private:
    std::string _my_string{some_string()};
}

//in cpp
constexpr const char* my_struct::some_string() noexcept
{
    return "Lorem ipsum dolor sit amet, consetetur sadipscing elitr,"
           "sed diam nonumy eirmod tempor invidunt ut labore et"
           " dolore magna aliquyam erat, sed diam voluptua.";
}

My compiler, g++ (Debian 4.9.2-10) 4.9.2, is complaining that some_string is undefined! Removing the constexpr-keyword solved the problem, but still whats the reason for this?

Is it some C++ rule I simply have missed or is it a compiler bug or neither of those options?

NaCl
  • 2,683
  • 2
  • 23
  • 37

0 Answers0