65,211
社区成员
发帖
与我相关
我的任务
分享void test_hash()
{
test_0 name[5];
for ( int i=0; i<5; ++i)
{
name[i].m = i+10;
g_testxx[i] = name[i];
}
}
int _tmain(int argc, _TCHAR* argv[])
{
test_hash();
stdext::hash_map<int ,test>::iterator it = g_testxx.begin();
for (; it!=g_testxx.end(); ++it)
{
cout<<it->first<<" "<<it->second.m<<endl;
}
return 0;
}我的疑问是,为什么test_hash()里存入局部的结构体对象,在hash-map里一样可以找得到值?name的作用域不是只在test_hash()里有效的吗?typedef struct test
{
int m;
}test_0;
stdext::hash_map<int ,test> g_testxx;
using namespace std;
void test_hash()
{
test_0 name[5];
for ( int i=0; i<5; ++i)
{
name[i].m = i+10;
g_testxx[i] = name[i];
}
}
int _tmain(int argc, _TCHAR* argv[])
{
test_hash();
stdext::hash_map<int ,test>::iterator it = g_testxx.begin();
for (; it!=g_testxx.end(); ++it)
{
cout<<it->first<<" "<<it->second.m<<endl;
}
return 0;
}