我想在名爲Map的類中創建MapIf
函數。 MapIf
將被稱爲像這樣:函數獲取函數指針和類指針?
void addThree(int& n) {
n += 3;
}
class startsWith {
char val;
public:
startsWith(char v) : val(v) {};
bool operator()(const std::string& str) {
return str.length() && char(str[0]) == val;
}
};
int main(){
...
startsWith startWithB('B');
Map<std::string, int> msi;
MapIf(msi, startWithB, addThree);
return 0;
}
會是什麼MapIf
的聲明?
void MapIf(const Map& map, class condition, void (*function)(ValueType));
可以嗎?
我不知道你是怎麼知道函數調用看起來像什麼,但不知道函數原型的。 –
映射爲std :: map(關聯容器)還是map-reduce? (對序列中的每個元素執行操作)。 可能在這裏,因爲你正在尋找一個關鍵字是否有一個謂詞,然後對它的值進行操作。 – CashCow