Different overloading function resolution in VS 2008/2010 and VS 2013

87 views Asked by At

I have a function with following definitions,

void ClassA::setLabel(int* newLabels){
  try{
    std::vector<int> labels(newLabels, newLabels + bonds.size());
    setLabel(labels);
  }
  catch(const std::exception& e){
    propogate_exception(e, "In function ClassA::setLabel(int*):");
  }
}

void ClassA::setLabel(const std::vector<int>& newLabels){
  try{
    std::set<int> labelS(&(newLabels[0]), &(newLabels[newLabels.size()]));
    if(!(bonds.size() == labelS.size())){
      throw std::runtime_error(exception_msg("Does not match."));
    }
    labels = newLabels;
  }
  catch(const std::exception& e){
    propogate_exception(e, "In function AClass::setLabel(std::vector<int>&):");
  }
}

And a section of the code is implemented as

ClassA M;
int labels[]={1,2,3,4};
M.setLabel(labels);

In Virtual C++ 2008 Pro and 2010 Pro, the call to setLabel is bound to the second definition, resulting in vector subscript out of range error; while in VC ++ 2013 it is bound to to the first definition.

I would expect a consistent binding to the first definition. My question is: (1) Why such different behaviors between versions of VC++? (2) Is there a better way to design and implement the interface to avoid such ambiguity?

Updated: I removed all my VS installations and used only VC++ 2008. Now the resolution is expected. Thanks everybody for help.

0

There are 0 answers