c++c++11vectormethod-callno-match

I keep getting the error "no match for call '(std::vector<int>) (int)"


Before reading this problem please note that this is a PRACTICE problem for hp codewars (a programming competition), I am not asking the forum about a real problem. My program is supposed to take the following input:

example:

The output should be the name of the person who had the closest guess

example:

I am currently coding the function that returns the closest number to the guess. However when I run the code, it gives me the error no match for call '(std::vector<int>) (int) on two lines. The lines that are sending back errors are pointed out in comments in my code.

Here is my code:

vector<int> compare(vector<int> nums, int loopnum, int ans){
  vector<int> buff2;
  for (int i = 0; i<loopnum;i++){
      vector<int>diff;
      int buff = ans - nums.at(i);
      for (int j = 0; j<loopnum; j++){
         diff.push_back(buff);
         for (int k = 0; k<diff.size(); k++){
             if (k == 0){
                buff2.push_back(diff.at(k));
             }
             else{
                 // this line is sending back an error
                 if ((abs(buff2(0))) > abs(diff.at(k))) {
                     buff2.clear();
                     buff2.push_back(diff.at(k));
                 }
                 // this line is also sending back an error
                 else if ((abs(buff2(0))) == abs(diff.at(k))){
                     buff2.push_back(diff.at(k));
                 }
             }
         }
      }
  }
  return buff2;
}

Please help me fix this!


Solution

  • buff2(0) should be buff2[0] or buff2.at(0)