global std::string and one definition rule
c++, one-definition-rule
Solution
`const` gives namespace-scoped variables internal linkage, that's why it works, effectively the same as
static const std::string error[] = {"a", "b"};
The second one doesn't work because it's not the variable that is const, but the `char`s it consists of.
Problem
I have a header file that contains the following definition ``` const std::string error[] = {"a", "b"}; ``` Now I'm including this file in two different translation units and compiling the source codes. Everything works, but why? This is expected to break `one definition rule`. Now even more interesting, I'm changing the type ``` const char* error[] = {"a", "b"}; ``` and here it is, expected error ``` multiple definition of `error' ``` It works the same way as for std::string for `int`, `char`, `short` and other integral types. What is this?