- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have explicitly enabled C++0x support in my project (latest C++ composer version) and I'm getting the above error. What is going on? The code I'm using is
static bimap<string, Type> typeNames = createTypeNames();
It doesn't seem like this works, and neither does inline initialization (i.e., typeNames = { { "Foo", Type::abc }}).
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Is typeNames being declared inside a class (i.e. a static data member)?
If so it is telling you that it needs to be declared const or constexpr (in c++11 mode). Since you are initializing it with a function call it must be constexpr and that function must itself be constexpr.
Example below. Compile with -DOK -std=c++11 it compiles fine but without -DOK it will give you the above error:
struct string {};
struct Type {};
template <class T, class T2>
struct bimap {
constexpr bimap() {}
};
constexpr bimap<string,Type> createTypeNames() {
return bimap<string, Type>();
}
struct C {
#ifdef OK
static constexpr bimap<string, Type> typeNames = createTypeNames();
#else
static bimap<string, Type> typeNames = createTypeNames(); // static data members must be const or constexpr
#endif
};
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page