获取地图中的值 - 地图包装类 [英] getting values in a map - map wrapper class

查看:115
本文介绍了获取地图中的值 - 地图包装类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个类作为std :: map的包装器。


该类是:

template< class TKey,class TValue>

类CGeneralMap:受保护地图< TKey,TValue>


目前我有基本功能,如添加,删除等,但我是

真的与GetValue挣扎,这就像从[key]获得的价值




例如,如果我创建一个:

CGeneralMap< int,std :: stringTestMap;


我有一个键3,其std :: string值为John。然后如何在我的

GetValue函数中提取John?

在我的GetValue函数中,我尝试过:


值= [3];


但这不起作用。

解决方案

10月2日上午12:28,Angus< anguscom ... @ gmail.comwrote:


我正在写一个类作为std的包装器: :地图。


课程是:

模板<类TKey,类TValue>

类CGeneralMap:受保护的地图< TKey ,TValue>


目前我有基本的功能,如添加,删除等,但我是

真的与GetValue挣扎,这将是获得的价值

来自[key]


例如,如果我创建一个:

CGeneralMap< int,std :: stringTestMap;


我有一个带有std :: string值John的键3。然后如何在我的

GetValue函数中提取John?


在我的GetValue函数中,我尝试过:


value = [3];


但这不起作用。



std :: string getKeyValue(int index)const

{

//代码......


返回TestMap [index];

}


-

Chris Val


10月1日,15:38,Chris(Val) < chris ... @ gmail.comwrote:


10月2日上午12:28,Angus< anguscom ... @ gmail.comwrote:



我正在编写一个类作为std :: map的包装器。


课程是:

模板< class TKey,类TValue>

class CGeneralMap :受保护的地图< TKey,TValue>


目前我有基本功能,如添加,删除等,但我是

真的在与GetValue挣扎,这将是如获得的价值

来自[key]


例如,如果我创建:

CGeneralMap< int,std :: stringTestMap;


我有一个键3,其std :: string值为John。然后如何在我的

GetValue函数中提取John?


在我的GetValue函数中,我试过:


value = [ 3];


但这不起作用。



std :: string getKeyValue(int index)const

{

//代码......


返回TestMap [index];

}


-

Chris Val - 隐藏引用的文字 -


- 显示引用的文字 -



我当然理解这一点。但我正在从我的班级内部讨论

。从我的GetValue函数中。


10月2日凌晨1点04分,Angus< anguscom ... @ gmail.comwrote:


10月1日,15:38,Chris(Val) < chris ... @ gmail.comwrote:



10月2日上午12:28,Angus< anguscom .. 。@ gmail.comwrote:


我正在编写一个类作为std :: map的包装器。


该类是:

template< class TKey,class TValue>

class CGeneralMap:protected map< TKey,TValue>


目前我有基本功能,如添加,删除等,但我是

真的与GetValue挣扎,这就像从[key]

<获得的价值

blockquote class =post_quotes>
例如,如果我创建一个:

CGeneralMap< int,std :: stringTestMap;


我有一个带有std :: string值为John的密钥3。然后如何在我的

GetValue函数中提取John?


在我的GetValue函数中,我试过:


value = [3];


但这不起作用。


std :: string getKeyValue(int index)const

{

//代码...


返回TestMap [index];

}


-

Chris Val-隐藏引用文字 -


- 显示引用的文字 -



我当然理解这一点。但我正在从我的班级内部讨论

。从我的GetValue函数中.-隐藏引用的文本 -



我缺少什么?

我展示的内容可以是成员函数你把它放在课堂上。


-

Chris Val


I am writing a class as a wrapper around a std::map.

The class is:
template<class TKey, class TValue>
class CGeneralMap : protected map<TKey, TValue>

At the moment I have basic functions like Add, Remove etc but I am
really struggling with GetValue, which will be like the value obtained
from [key]

Eg if I create a:
CGeneralMap<int, std::stringTestMap;

and I have a key 3 with std::string value of John. then how in my
GetValue function do I extract the "John"?
In my GetValue function I tried:

value = [3];

but that doesn''t work.

解决方案

On Oct 2, 12:28 am, Angus <anguscom...@gmail.comwrote:

I am writing a class as a wrapper around a std::map.

The class is:
template<class TKey, class TValue>
class CGeneralMap : protected map<TKey, TValue>

At the moment I have basic functions like Add, Remove etc but I am
really struggling with GetValue, which will be like the value obtained
from [key]

Eg if I create a:
CGeneralMap<int, std::stringTestMap;

and I have a key 3 with std::string value of John. then how in my
GetValue function do I extract the "John"?

In my GetValue function I tried:

value = [3];

but that doesn''t work.


std::string getKeyValue( int index ) const
{
// Code...

return TestMap[ index ];
}

--
Chris Val


On 1 Oct, 15:38, "Chris ( Val )" <chris...@gmail.comwrote:

On Oct 2, 12:28 am, Angus <anguscom...@gmail.comwrote:


I am writing a class as a wrapper around a std::map.

The class is:
template<class TKey, class TValue>
class CGeneralMap : protected map<TKey, TValue>

At the moment I have basic functions like Add, Remove etc but I am
really struggling with GetValue, which will be like the value obtained
from [key]

Eg if I create a:
CGeneralMap<int, std::stringTestMap;

and I have a key 3 with std::string value of John. then how in my
GetValue function do I extract the "John"?

In my GetValue function I tried:

value = [3];

but that doesn''t work.


std::string getKeyValue( int index ) const
{
// Code...

return TestMap[ index ];
}

--
Chris Val- Hide quoted text -

- Show quoted text -

Yes of course I understand that. But I am talking about from within
my class. From within my GetValue function.


On Oct 2, 1:04 am, Angus <anguscom...@gmail.comwrote:

On 1 Oct, 15:38, "Chris ( Val )" <chris...@gmail.comwrote:


On Oct 2, 12:28 am, Angus <anguscom...@gmail.comwrote:

I am writing a class as a wrapper around a std::map.

The class is:
template<class TKey, class TValue>
class CGeneralMap : protected map<TKey, TValue>

At the moment I have basic functions like Add, Remove etc but I am
really struggling with GetValue, which will be like the value obtained
from [key]

Eg if I create a:
CGeneralMap<int, std::stringTestMap;

and I have a key 3 with std::string value of John. then how in my
GetValue function do I extract the "John"?

In my GetValue function I tried:

value = [3];

but that doesn''t work.

std::string getKeyValue( int index ) const
{
// Code...

return TestMap[ index ];
}

--
Chris Val- Hide quoted text -

- Show quoted text -


Yes of course I understand that. But I am talking about from within
my class. From within my GetValue function.- Hide quoted text -

What am I missing?
What I showed you can be a member function if you put it in a class.

--
Chris Val


这篇关于获取地图中的值 - 地图包装类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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