Hi,
I was happy that I found a STL way to copy elements using a functional condition :
However, when I attempted to encapsulate this into a class I ran into problems :
This gives the compile error :
'FileExistsCopy::FileNotExists': function call missing argument list; use '&FileExistsCopy::FileNotExists' to create a pointer to member.
This is because FileNotExists is not static, but I need to use the member data in the static function.
Any Suggestions ?
Regards,
Rich.
Programmers are tools for converting caffeine into code
I was happy that I found a STL way to copy elements using a functional condition :
Code:
bool FileNotExists(string Filename)
{
return (FileExists(Filename.c_str()) == FALSE);
}
int main()
{
vector<string> filenames;
filenames.push_back( string("C:\\File1.txt") );
filenames.push_back( string("C:\\File2.txt") );
filenames.push_back( string("C:\\File3.txt") );
filenames.push_back( string("C:\\File4.txt") );
filenames.push_back( string("C:\\File5.txt") );
filenames.push_back( string("C:\\File6.txt") );
vector<string> existingFiles;
// get a vector of files that Exist on the hard disk.
// Note: the remove_copy_if only copies elements where
// the function returns false, therefore use FileNotExists
remove_copy_if( filenames.begin(), filenames.end(),
inserter(existingFiles, existingFiles.begin()),
FileNotExists );
}
However, when I attempted to encapsulate this into a class I ran into problems :
Code:
FileExistsCopy::FileExistsCopy(vector<string>& filenames)
{
m_CurrentDirectory = getCurrentDirectory();
remove_copy_if(filenames.begin(), filenames.end(),
inserter(m_existingFiles, m_existingFiles.begin()),
FileNotExists);
}
bool FileExistsCopy::FileNotExists(string Filename)
{
// build the path using m_CurrentDirectory
string strFilename = m_CurrentDirectory + string("\\") + Filename;
return (FileExists(strFilename) == FALSE);
}
string FileExistsCopy::getCurrentDirectory() const
{
// ...
}
This gives the compile error :
'FileExistsCopy::FileNotExists': function call missing argument list; use '&FileExistsCopy::FileNotExists' to create a pointer to member.
This is because FileNotExists is not static, but I need to use the member data in the static function.
Any Suggestions ?
Regards,
Rich.
Programmers are tools for converting caffeine into code