void f1(string txt)const { for_each(txt.begin(),txt.end(),f2) } void f2(char a)const { //用信件做东西 } } 这是我想要完成的概要,但我无法接受f2。我试过mem_fun(f2),ptr_fun(f2)。但我有一种感觉,我是这样的。我会感激任何帮助我可以得到Hi, I''m having trouble with for_each. Setup: class test { void f1(string txt) const { for_each(txt.begin(),txt.end(),f2) } void f2(char a) const { //do stuff with letters }} This is the general outline of what i want to accomplish, but i can''t get foreach to accept f2. I''ve tried mem_fun(f2), ptr_fun(f2). But I''ve got a feeling I''m way of. I''d appreciate any help i can get推荐答案 你的for_each方法是什么?为什么要将函数名称传递给其他函数?what is your for_each method? Why are you passing a function name to your other function? 你的for_each方法是什么?为什么要将函数名称传递给其他函数? what is your for_each method? Why are you passing a function name to your other function? for_each(begin,end,f)是一个STL算法,带有两个迭代器和一个函数对象。我的问题是如何让函数f2作为一个参数。 我的问题可以用循环来解决 for(it = begin,it< ;结束,它++) f2(txt(it)); 但是为了知识,我想知道它是如何完成的在STL中for_each(begin, end, f) is a STL -algorithm, taking two iterators, and a funtion object. My problem is how to make it take the function f2 as an argument. My problem could be solved with a loopfor(it=begin, it<end, it++) f2(txt(it)); but for the sake of knowledge, I''d like to know how its done in STL 您是否编写了for_each方法?如果是这样,那么你可以在这里张贴一些CODE标签,以便我可以看看吗?Did you write the for_each method? If so then can you post it here with some CODE tags around it so that I can take a look? 这篇关于STL算法问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-19 17:24