0

I'm not sure why I'm getting a compiler error. Here's a snippet of my code

 vector<int> weights(m, 0);
  collect_weights(adjA, weights);
  /*******   Find the median of weights *********/
  int k = m >> 1;//divide by 2
  if(m % 2 == 0)
    k--;
  int median_weight = select(weights,0,m-1,k); //compiler error here

Here's my function declaration:

int select(vector<int> &v, int start, int fin, int k);

and here's my compiler error:

cannot convert ‘std::vector<int>’ to ‘int’ for argument ‘1’ to ‘int select(int, fd_set*, fd_set*, fd_set*, timeval*)’
         int median_weight = select(weights, 0, m,k);

It seems in my compiler error that select is expecting 5 arguments with the first one being an int, however, based on my function declaration, there should be only 4 (first one being vector of ints). Is there anything I've overlooked by any chance?

BTW, it works when I call select here:

int find_median = select(v, 0, v.size()-1, mid);

with v being the vector of ints I pass into the function

Mike1982
  • 439
  • 10
  • 26
  • 1
    Impossible to tell without seeing a [MCVE]. – πάντα ῥεῖ Sep 23 '18 at 21:04
  • 2
    Apparently, it confuses your function with the Linux [`select` system call](http://man7.org/linux/man-pages/man3/FD_SET.3.html). – ForceBru Sep 23 '18 at 21:05
  • 2
    It appears that you haven't declared your `select` function before you call it, so it is finding one in the standard library (because you have a `using namespace std;`, which you [shouldn't use](https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice), somewhere earlier n your code). – 1201ProgramAlarm Sep 23 '18 at 21:06
  • oh wow ok, that fixed it. Didn't realize there was a built in c++ function already called select. I just moved my select function up before the function that calls it and compiler error went away. Thanks, I'll also fix the using namespace std, by only specifying cin and cout. – Mike1982 Sep 23 '18 at 21:13

0 Answers0