initializing static const map
OK. I've seen several posts on the subject in
the archives, but I still seem to be stuck.
Perhaps someone with fresher, more knowledgeable
eyes can tell me what I'm doing wrong?
I'm getting the error:
mapinit.cpp:15: error: expected initializer before 'A'
when I try to compile the following, and for the
life of me I can't figure out WHY. Anyone?
(I've tried several variations of this, including
declaring _init_mapconst() as const, and not using
inline, etc. Same error each time.)
Any assistance welcome.
thanks,
Marc
// minimal example of map initialization problem:
#include <string>
#include <map>
class A {
private:
typedef std::map<std::string, int> maptype_t;
static const maptype_t _mapconst;
static maptype_t _init_mapconst();
}
inline A::maptype_t
A::_init_mapconst() // line 15
{
maptype_t m;
m["aaa"] = 23;
m["acb"] = 42;
return m;
}
const A::maptype_t
A::_mapconst =
A::_init_mapconst();
int main()
{
}
/* compilation attempt:
$$> g++ -Wall -pedantic -ansi mapinit.cpp -o mapinit
mapinit.cpp:15: error: expected initializer before 'A'
$$> g++ --version
g++ (GCC) 4.0.2
*/
--
Marc D.
(note that reply-to is a black hole.]
Use list [at] ryuu in Canada to send email.
Or, preferably, reply here...