I need to define a static member (not constexpr) with a complex (many template parameters) type. Therefore it would be desired to have something like this:
struct X {
static auto x = makeObjectWithComplexType();
};
But it is not C++. So I tried to workaround it, and thought the snippet below would work, but it does not:
#include <string>
struct X {
static auto abc() {
return std::string();
}
static decltype(abc()) x;
};
decltype(abc()) X::x;
int main() {}
It fails with error: error: use of ‘static auto X::abc()’ before deduction of ‘auto`*
Is there any way to make the snippet above to work. Or is there any other way to define a static member with a deduced type?