I'm trying to create static constexpr
s defined inside the class. I know about this question: static constexpr member of same type as class being defined, and method 3 works fine now.
However, I have a problem with the linker. It reports of duplicate symbols, probably because of the const
to constexpr
redefinition. Is there a way to accomplish this? I am using xcode 7.
The code I am trying is:
class foo{
int _x;
constexpr foo(int x) : _x(x) {}
public:
static const foo a, b, c;
constexpr int x() const { return _x; }
};
constexpr foo foo::a = foo(1), foo::b = foo(2), foo::c = foo(1);
Including this file in more than one place causes a linker error stating
3 duplicate symbols for architecture x86_64
I know this is the problem, because if I only include it once it works fine.