This引用的for_each如下:有没有什么办法让for_each参考?
template<class InputIterator, class Function>
Function for_each(InputIterator first, InputIterator last, Function f);
我有一个集合std::list<std::string>
,并且在与迭代器一起给for_each
void Do(std::string)
正常工作的功能。但是如果我提供像void Do(std::string&)
这样的函数,它不会编译。有没有办法解决它?或者我应该忘记一些像魔术一样的RVO? :d
编辑:
bool PluginLoader::LoadSharedObjects()
{
for_each(l_FileNames.begin(), l_FileNames.end(), bind1st(mem_fun(&PluginLoader::LoadSharedObject),this));
}
void PluginLoader::LoadSharedObject(const std::string sFileName)
{
void* pHandle = dlopen(sFileName.c_str(), i_LibMode);
//if(pHandle == NULL)
//Check dlerror
//Add handle to list
}
代码加入。如果可能的话,我需要LoadSharedObject
函数的形式为void PluginLoader::LoadSharedObject(const std::string& sFileName)
。
请显示一些代码。 :) – 2010-10-13 07:03:49