Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   initializing static const map (http://www.velocityreviews.com/forums/t460458-initializing-static-const-map.html)

Marc D 02-14-2007 12:04 AM

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...

Ian Collins 02-14-2007 12:12 AM

Re: initializing static const map
 
Marc D wrote:
> 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.)


> class A {
> private:
> typedef std::map<std::string, int> maptype_t;
>
> static const maptype_t _mapconst;
> static maptype_t _init_mapconst();
> }
>

Missing semicolon!

--
Ian Collins.

Marc D 02-14-2007 01:52 AM

Re: initializing static const map
 
Ian Collins wrote:
> Marc D wrote:

[...]
>> }
>>

> Missing semicolon!
>


::beats head against large brick wall::

Thanks for that! You have no idea how long I've
looked at the original problem, and this reduced
set...

need sleep.


--
Marc D.


All times are GMT. The time now is 06:30 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.