包含pointer_to_binary_function的STL映射 [英] STL map containing pointer_to_binary_function
问题描述
大家好,
我正在靠墙试图找出如何制作
这项工作。
我有一个地图,其中包含一个字符串作为键,我希望数据为
是一个pointer_to_binary_function,但在地图定义时,我
不知道类型。所以地图中包含了一个模板化的
pointer_to_binary_function。当我实际添加到地图的时候,我知道二元函数的类型。
添加到地图:
mMap.insert(" test",ptr_fun(not_equal_to< int>));
失败:错误:在''之前预期的promary-expression''''令牌
我在这里不知所措。
谢谢
格伦
Hi All,
I am beating my head against the wall trying to figure out how to make
this work.
I have a map which contains a string as the key and I want the data to
be a pointer_to_binary_function, but at the time of map definition, I
don''t know the types. So really the map contains a templatized
pointer_to_binary_function. When I actually add to the map is where I
know the types of the binary function.
Adding to the map:
mMap.insert("test", ptr_fun(not_equal_to<int>));
Fails with: error: expected promary-expression before '')'' token
I am at a loss here.
Thanks
Glenn
推荐答案
Gl ****** @ gmail .com 写道:
我正在试图弄清楚如何制作
这项工作。
我有一个地图,其中包含一个字符串作为键,我希望数据
是一个pointer_to_binary_function,但在地图定义时,我
我不知道这些类型。
I am beating my head against the wall trying to figure out how to make
this work.
I have a map which contains a string as the key and I want the data to
be a pointer_to_binary_function, but at the time of map definition, I
don''t know the types.
然后你没有物体。没有办法绕过它,如果你想要定义一个对象,你需要给它一个具体的类型。
Then you don''t have an object. There is no way around it, if you want
to define an object, you need to give it a concrete type.
所以真的地图包含一个模板化的
pointer_to_binary_function。
So really the map contains a templatized
pointer_to_binary_function.
这是胡说八道,对不起。
That''s nonsense, sorry.
当我真正添加到地图的时候我就在哪里
知道二元函数的类型。
When I actually add to the map is where I
know the types of the binary function.
如果您想要添加时知道它,那么在构建地图时应该能够知道
。这一切都发生在你编码的时候。
If you know it when you want to add, you should be able to know it
when you construct your map. It all happens while you''re coding.
添加到地图:
mMap.insert(" test" ;,ptr_fun(not_equal_to< int>));
失败:错误:''之前预期的promary-expression'''令牌
$ b $我在这里不知所措。
Adding to the map:
mMap.insert("test", ptr_fun(not_equal_to<int>));
Fails with: error: expected promary-expression before '')'' token
I am at a loss here.
一个像代码一样*不够*了解如何让你回到
轨道。请解释你试图解决的问题。
V
-
请删除大写''A'在通过电子邮件回复时
我没有回复最热门的回复,请不要问
One like of code is *not enough* to understand how to get you back on
track. Please explain the problem you''re trying to solve.
V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask
Gl ****** @ gmail.com 写道:
大家好,
我正在靠墙试图找出如何制作
这项工作。
我有一个地图,其中包含一个字符串作为键,我希望数据
是一个pointer_to_binary_function,但在地图定义时,我
don不知道类型。所以地图中包含了一个模板化的
pointer_to_binary_function。当我实际添加到地图的时候,我知道二元函数的类型。
添加到地图:
mMap.insert(" test",ptr_fun(not_equal_to< int>));
Hi All,
I am beating my head against the wall trying to figure out how to make
this work.
I have a map which contains a string as the key and I want the data to
be a pointer_to_binary_function, but at the time of map definition, I
don''t know the types. So really the map contains a templatized
pointer_to_binary_function. When I actually add to the map is where I
know the types of the binary function.
Adding to the map:
mMap.insert("test", ptr_fun(not_equal_to<int>));
ptr_fun适应免费功能,但not_equal_to是模板仿函数类
ptr_fun adapts a free function, but not_equal_to is template functor class
>
失败:错误:''之前预期的promary-expression'''令牌
我在这里不知所措。
谢谢
格伦
>
Fails with: error: expected promary-expression before '')'' token
I am at a loss here.
Thanks
Glenn
-
谢谢
Barry
--
Thanks
Barry
感谢您的信息。
让我明确我的目标,我希望地图包含一个字符串作为关键
和一个函数指针模板作为数据。意思是,我想在地图中插入以下内容:
map [" test"] = equal_to< string> ;; //或指向
binary_function ....
map [" test1"] = equal_to< int> ;;
map [ " test2"] = less< double>;
等...
我知道所有这些仿函数的基本模板是binary_function
模板。
是否有可能有一个数据为binary_function的地图
模板?
谢谢
Glenn
8月29日凌晨2:58,Barry< dh ...... @ 126.comwrote:
Thanks for the info.
Let me clearify my goal, I want a map to contain a string as the key
and a function pointer template as the data. Meaning, I want to insert
into the map the following things:
map["test"] = equal_to<string>; // or pointers to the
binary_function....
map["test1"] = equal_to<int>;
map["test2"] = less<double>;
etc...
I know the base template for all those functors is the binary_function
template.
Is it possible to have a map where the data is a binary_function
template?
Thanks
Glenn
On Aug 29, 2:58 am, Barry <dh...@126.comwrote:
Glenn ... @ gmail.com写道:
Glenn...@gmail.com wrote:
大家好,
Hi All,
我正在试图弄清楚如何制作
这项工作。
I am beating my head against the wall trying to figure out how to make
this work.
我有一个地图,其中包含一个字符串作为键,我想要数据
是一个pointer_to_binary_function,但是在地图定义时,我
不知道类型。所以地图中包含了一个模板化的
pointer_to_binary_function。当我实际添加到地图中时,我知道二进制函数的类型。
I have a map which contains a string as the key and I want the data to
be a pointer_to_binary_function, but at the time of map definition, I
don''t know the types. So really the map contains a templatized
pointer_to_binary_function. When I actually add to the map is where I
know the types of the binary function.
添加到地图:
Adding to the map:
mMap.insert(" ; test",ptr_fun(not_equal_to< int>));
mMap.insert("test", ptr_fun(not_equal_to<int>));
ptr_fun适应免费功能,但not_equal_to是模板仿函数类
ptr_fun adapts a free function, but not_equal_to is template functor class
失败:错误:预期promary-expression before'')''token
Fails with: error: expected promary-expression before '')'' token
我在这里不知所措。
I am at a loss here.
谢谢
Thanks
Glenn
Glenn
-
谢谢
Barry
--
Thanks
Barry
这篇关于包含pointer_to_binary_function的STL映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!