Mark B and Vlad from Moscow, answer why I just answer, as you can name them.
you must add explicit to avoid implicit compiler conversion
#include <iostream> struct X {}; struct O { explicit O(X) { ; } O() = default; O(O const &) = default; O(O &&) = default; }; struct S { void f(X) const { ; } void f(O) { ; } }; #include <cstdlib> int main() { S s; sf(X{}); return EXIT_SUCCESS; }
EDIT
if your type O is in 3party lib you can add a template for this.
#include <iostream> using namespace std; struct X {}; struct O { O(X) { ; } O() = default; O(O const&) = default; O(O&&) = default; }; struct S { void f(const X) const { cout << "X" << endl; } void f(O) { cout << "O" << endl; } };
source share