Skip to content

about constexpr to define string& variable #94

@huidui

Description

@huidui

why i can define :
const std::string& s1 = "test";
or
const std::string s1 = "test";
but if i try to define s1 with constexpr, my VS2019 report error
constexpr std::string& s1 ="test'; (due to constexpr only can define reference , pointer, or literal values, so i define string&.
i am confused, why const define pass, but constexpr will fail ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions