文字列のベクトルを設定するインスタンス メソッドがあります。特定の部分文字列を含む 1 つのベクトル エントリを見つけようとしています (今のところ、その部分文字列は固定されています - シンプルです)。
私は持ってい.h
ます:
namespace Data
{
namespace Shared
{
class Logger
{
public:
bool FindLogDirectoryPredicate(const string &str);
int GetLogDirectory(string logConfigFile, string& logDirectory);
...
}
}
}
と.cpp
:
#include <algorithm>
#include <vector>
#include "Logger.h"
bool Logger::FindLogDirectoryPredicate(const string &str)
{
// Return false if string found.
return str.find("File=") > 0 ? false : true;
}
int Logger::GetLogDirectory(string logConfigFile, string& logDirectory)
{
vector<string> fileContents;
...
vector<string>::iterator result = find_if(fileContents.begin(), fileContents.end(), FindLogDirectoryPredicate);
...
}
これを Visual Studio 2010 でコンパイルすると、次のようになります。
Error 7 error C3867: 'Data::Shared::Logger::FindLogDirectoryPredicate': function call missing argument list; use '&Data::Shared::Logger::FindLogDirectoryPredicate' to create a pointer to member Logger.cpp 317 1 Portability
find_if 呼び出しで関数 ref の前に & をスローすると、次のようになります。
Error 7 error C2276: '&' : illegal operation on bound member function expression Logger.cpp 317 1 Portability
述語関数をクラスの外に置こうとしましたが、うまくいかなかったようで、関数が見つからないというエラーが発生しました。クラス名で述語を修飾しようとしました...アルゴリズム(ヘッダー)で別のエラーが発生しました:
Error 1 error C2064: term does not evaluate to a function taking 1 arguments c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\algorithm 83 1 Portability
私がここからフォローしていた例は、これが比較的単純であることを示しているようです....では、何が間違っているのでしょうか?