这把我逼到了墙边。
template<typename t>
void Tree<t>::readFromFile(string filename)
{
//
str.erase( remove_if(str.begin(), str.end(), aZCheck), str.end());
//
}
template<typename t>
bool Tree<t>::aZCheck(char c)
{
if (isalpha(c))
return false;
else return true;
}
给出错误:cannot convert 'Tree<t>::aZCheck<std::basic_string<char> >' from type 'bool (Tree<std::basic_string<char> >::)(char)' to type 'bool (Tree<std::basic_string<char> >::*)(char)'|
在我将这两个方法移到类中之前工作正常。
str.erase( remove_if(str.begin(), str.end(), isalpha), str.end());
不使用静态转换就无法工作,我使用的是 cctype 或 ctype.h 库,静态转换适用于我未使用的 c++ 语言环境库。
我可以使用静态转换让它工作,但我似乎无法将其设为负值 !isalpha
.
因为我需要删除非字母字符,所以它会删除字母字符。迫使我创建单独的方法,这是我提到的第一个问题。在我将方法移入类之前,它一直有效。
很可能我遗漏了一些非常明显的东西,但我就是想不通......
最佳答案
将函数声明为静态成员函数
static bool aZCheck(char c);
考虑到函数可以定义得更简单
template<typename t>
inline bool Tree<t>::aZCheck( char c )
{
return isalpha( (unsigned char )c );
}
关于c++ - 从字符串c++中删除非字母字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26918841/