The thing what I want to do is just replacing one field of structure on the vector of structure if the condition was satisfied . So here is my code:
struct DataST{
int S_num,Charge,Duplicate_Nu;
float PEP;
string PEPTIDE;
vector<MZIntensityPair> pairs;
bool GetByT(const DataST& r,int T)
{
switch (T)
{
case 1:
return (S_num == r.S_num);
case 2:
return (Charge == r.Charge);
case 3:
return !(PEPTIDE.compare(r.PEPTIDE));
case 4:
return (Duplicate_Nu == r.Duplicate_Nu);
case 5:
return ((S_num == r.S_num)&&(Charge == r.Charge));
default:
return false;
}
}
};
int main()
{
.
.
vector<DataST> spectrums;
.
.
DataST tempDT_dup;
tempDT_dup.PEPTIDE="Test";
replace_if(spectrums.begin(), spectrums.end(), boost::bind(&DataST::GetByT, _1,tempDT_dup,3),11);
.
.
}
So in this examle I want to change all the Duplicate_Nu of spectrums items with 11 if the PEPTIDE filed of that item is equal to "test" but I got error below while I want to use function GetByT instead of operation "="
/usr/include/c++/4.6/bits/stl_algo.h:4985:4: error: no match for ‘operator=’ in ‘_first._gnu_cxx::__normal_iterator<_Iterator, _Container>::operator* with _Iterator = DataST*, _Container = std::vector, __gnu_cxx::__normal_iterator<_Iterator, _Container>::reference = DataST& = __new_value’ /usr/include/c++/4.6/bits/stl_algo.h:4985:4: note: candidate is: hello_pwiz/hello_pwiz.cpp:14:8: note: DataST& DataST::operator=(const DataST&) hello_pwiz/hello_pwiz.cpp:14:8: note: no known conversion for argument 1 from ‘int DataST::* const’ to ‘const DataST&’