2014-02-11 34 views
3

由於「error:沒有匹配函數調用'mem_fun_ref()'」(gcc版本4.4.6),下面的代碼將不會編譯。mem_fun_ref:無法解析的重載函數類型

#include <vector> 
#include <string> 
#include <string.h> 
#include <algorithm> 
#include <iostream> 

using namespace std; 

class toto 
{ 
    char v[10]; 

public: 
    toto(char* t) { memcpy(v, t, 9); } 
    bool test(const char* var) const { return !strncmp(var, v, 9); } 
    bool test(const string& var) const { return test(var.c_str()); } 
}; 

int main() 
{ 
    vector<toto> t; 
    t.push_back("1"); 
    t.push_back("2"); 

    string name("2"); 
    vector<toto>::iterator it = remove_if(t.begin(), t.end(), 
     bind2nd(mem_fun_ref(&toto::test), name)); // <= error 
    t.erase(it, t.end()); 
    return 0; 
} 

我找到了一個解決辦法:創建

bool testZ(const string& var) const { return testZ(var); } 

但我似乎無法找到正確的模板參數,如果這甚至有可能,給予mem_fun_ref使(或bind2nd?)它沒有我的解決方法編譯。

有沒有辦法解決這個問題,或者解決方法是「首選」方法?

+0

你看到[升壓::綁定(http://www.boost.org/doc/libs/1_55_0/libs/bind /bind.html)? – P0W

+0

我們不允許在我們的項目中使用增強功能,以最大限度地兼容神祕平臺。 – BlakBat

回答

相關問題