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