You can accomplish something similar in C++ by providing an explicit cast to the desired type.
struct Foo
{
Foo(int /*bar*/) {}
Foo(int &/*bar*/) {}
};
int main()
{
int value = 5;
Foo foo(static_cast<const int&>(value));
return 0;
}
The cast to const
will cause overload resolution to ignore the constructor taking a non-const reference and will settle on passing by value.