Compare the following:
I have a static member in a class that is either const constexpr
or just constexpr
. According to this explanation on MS Docs constexpr implies constness:
All constexpr variables are const.
However, this issues a warning in gcc 8.4:
#include <iostream>
#include <string>
struct some_struct
{
static constexpr char* TAG = "hello";
void member() {
printf("printing the tag %s", TAG);
}
};
int main()
{
some_struct A;
A.member();
}
While this doesn't:
#include <iostream>
#include <string>
struct some_struct
{
static const constexpr char* TAG = "hello";
void member() {
printf("printing the tag %s", TAG);
}
};
int main()
{
some_struct A;
A.member();
}
What is the difference?