Differential resolution of overload function in VS 2008/2010 and VS 2013
I have a function with the 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 the code section is implemented as
ClassA M;
int labels[]={1,2,3,4};
M.setLabel(labels);
In Virtual C ++ 2008 Pro and 2010 Pro, the call is setLabel
tied to the second definition, which results in an error vector subscript out of range
; while in VC ++ 2013 it is linked to the first definition.
I would expect a consistent binding to the first definition. My question is: (1) Why is there such different behavior between VC ++ versions? (2) Is there a better way to design and implement an interface to avoid such ambiguity?
Updated: I removed all VS installations and only used VC ++ 2008. Resolution is now awaiting. Thanks everyone for the help.
source to share
No one has answered this question yet
Check out similar questions: