Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Ambiguity when calling overloaded function with vector as param

I am writing a class in which I am overloading operator[] and I want one function to have vector as input and the second one to have vector of vectors as input, but when I call it like

obj[{ 0 }]

then I got ambigious call error. The functions are declared like

const Tensor operator[](const std::vector<std::vector<uint32_t>>& ranges) const;
const float operator[](const std::vector<uint32_t>& index) const;

Is there any way to handle that ambiguity?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The compiler has no way of knowing by seeing the argument {0} which one to choose among the two equally ranked overloads.

One way to resolve the ambiguity is to explicitly tell the compiler as shown below:

obj[std::vector<uint32_t>{0}]; //calls #2
obj[std::vector<std::vector<uint32_t>>{0}]; //calls #1
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading