Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/147.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;向量移除if对_C++_Data Structures_Stdvector - Fatal编程技术网

C++ C++;向量移除if对

C++ C++;向量移除if对,c++,data-structures,stdvector,C++,Data Structures,Stdvector,我试图用remove_if从向量中删除对,但是我得到了错误 bool MyClass::isSingleTag(const pair<int,string> & val) { string tag = val.second; int posImg, posBr; posImg = tag.find("<img"); posBr = tag.find("<br"); if (posImg == -1 && posBr =

我试图用remove_if从向量中删除对,但是我得到了错误

bool MyClass::isSingleTag(const pair<int,string> & val) {
   string tag = val.second;
   int posImg, posBr;
   posImg = tag.find("<img");
   posBr = tag.find("<br");
   if (posImg == -1 && posBr == -1) {
      return false;
   } else {
      return true;
   }
}
void MyClass::deleteSingleTags() {
   vector<pair<int,string>>::iterator last_iter;
   last_iter = remove_if(allTags.begin(), allTags.end(), &MyClass::isSingleTag);
   allTags.erase(last_iter, allTags.end());
}
bool MyClass::isSingleTag(const pair&val){
字符串标记=val.second;
int posImg,posBr;

posImg=tag.find(“如果没有函数所属类的对象,则无法调用指向成员函数的指针

使
isSingleTag
静态
-获取其地址将生成一个普通函数指针。或者,将其设置为自由函数,因为它看起来一开始作为成员函数就没有任何业务(它不会访问任何其他成员,是吗?)

另一个选项(当您合法地需要成为成员函数时)是使用
std::bind

MyClass obj;
auto func = std::bind(&MyClass::isSingleTag, obj);

现在func是一个可调用函数,您可以将其传递给算法。

错误是什么?他的错误是他试图传递一个PTMF作为谓词。我将冒险猜测
isSingleTag
没有声明
static
,因此如果
则不能作为
remove\u的谓词。您不显示声明符ion-isSingleTag是静态的吗?您好,vegazz!您在这里提供的信息不足以帮助我们诊断错误。您能否提供更多信息,例如您遇到的具体错误(编译时错误?如果是,什么?运行时错误?如果是,什么类型?)或者有足够的代码让我们能够在我们这边重现错误?谢谢!