为什么不能在块之外填充静态映射 [英] Why is it no possible to fill a static map outside of a block

查看:95
本文介绍了为什么不能在块之外填充静态映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,


课堂定义


class X {


private :

静态地图< string,map< string,int word_map;

static void initialize();

};


并在实现文件中,我可以在任何功能块之外的

功能块内填写地图。之前我问过这个问题

并得到一个回复​​,建议将这些行放入初始化程序

函数中。这很好但我想知道为什么我无法在功能块之外定义和确定
initiliaze。 as


word_map [" try"]。insert(make_pair(" try",1));


和外面的条目任何功能。这与

静态有关但无法解决这个问题。


谢谢

解决方案

我忘了写我输入


map< string,map< string,int word_map;


first。


utab schreef:


亲爱的,


课堂定义


class X {


私人:

静态地图< string,map< string,int word_map;

static void initialize();

};


并在实现文件中,我可以在任何功能块之外的

功能块内填写地图。之前我问过这个问题

并得到一个回复​​,建议将这些行放入初始化程序

函数中。这很好但我想知道为什么我无法在功能块之外定义和确定
initiliaze。 as


word_map [" try"]。insert(make_pair(" try",1));


和外面的条目任何功能。这与

静态相关,但无法解决这个问题。


感谢


我忘了写我输入


map< string,map< string,int word_map;


first。


utab schreef:


亲爱的,


课堂定义


class X {


私人:

静态地图< string,map< string,int word_map;

static void initialize();

};


并在实现文件中,我可以在任何功能块之外的

功能块内填写地图。之前我问过这个问题

并得到一个回复​​,建议将这些行放入初始化程序

函数中。这很好但我想知道为什么我无法在功能块之外定义和确定
initiliaze。 as


word_map [" try"]。insert(make_pair(" try",1));


和外面的条目任何功能。这与

静态相关,但无法解决这个问题。


感谢


12月19日下午4:52,utab < umut.ta ... @ gmail.comwrote:


亲爱的,


在类定义中


class X {


private:

静态地图< string,map< string,int word_map;

static void initialize();


};


和在实现文件中,我可以在任何功能块之外的

功能块内填写地图。之前我问过这个问题

并得到一个回复​​,建议将这些行放入初始化程序

函数中。这很好但我想知道为什么我无法在功能块之外定义和确定
initiliaze。 as


word_map [" try"]。insert(make_pair(" try",1));


和外面的条目任何功能。这与

静态相关,但无法解决这个问题。



函数块之外的代码永远不会被执行,它只是关于应用程序启动时应该知道什么的信息。但地图

在此之前不存在。


-

Erik Wikstr?m


Dear all,

in a class definition

class X{

private:
static map< string , map<string, int word_map;
static void initialize();
};

and in the implementation file, I may fill out the map inside the
function block not outside any function block. I asked this question
before and got a reply advicing to put those lines in an initializer
function. This works fine but I wondered why I could not define and
initiliaze outside the function block. As

word_map["try"].insert(make_pair("try",1));

and the entries outside any of the functions. This is sth related to
static but could not figure that out.

thanks

解决方案

I forgot to write I type

map< string , map<string, int word_map;

first.

utab schreef:

Dear all,

in a class definition

class X{

private:
static map< string , map<string, int word_map;
static void initialize();
};

and in the implementation file, I may fill out the map inside the
function block not outside any function block. I asked this question
before and got a reply advicing to put those lines in an initializer
function. This works fine but I wondered why I could not define and
initiliaze outside the function block. As

word_map["try"].insert(make_pair("try",1));

and the entries outside any of the functions. This is sth related to
static but could not figure that out.

thanks


I forgot to write I type

map< string , map<string, int word_map;

first.

utab schreef:

Dear all,

in a class definition

class X{

private:
static map< string , map<string, int word_map;
static void initialize();
};

and in the implementation file, I may fill out the map inside the
function block not outside any function block. I asked this question
before and got a reply advicing to put those lines in an initializer
function. This works fine but I wondered why I could not define and
initiliaze outside the function block. As

word_map["try"].insert(make_pair("try",1));

and the entries outside any of the functions. This is sth related to
static but could not figure that out.

thanks


On Dec 19, 4:52 pm, "utab" <umut.ta...@gmail.comwrote:

Dear all,

in a class definition

class X{

private:
static map< string , map<string, int word_map;
static void initialize();

};

and in the implementation file, I may fill out the map inside the
function block not outside any function block. I asked this question
before and got a reply advicing to put those lines in an initializer
function. This works fine but I wondered why I could not define and
initiliaze outside the function block. As

word_map["try"].insert(make_pair("try",1));

and the entries outside any of the functions. This is sth related to
static but could not figure that out.

Code outside a function-block is never executed, it''s just information
about what should be known when the application starts. But the map
does not exist before then.

--
Erik Wikstr?m


这篇关于为什么不能在块之外填充静态映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆