I have a class that has a conversion operator to int& that I want to hide. I created a derived class that only offers a conversion to int and made the conversion to int& private. But I still cannot make the int conversion to be used, either the compiler tells me that the conversion is ambiguous, or insists to use the int& conversion and tells me it is inaccessible. How do I make this work?
struct Base {
int value;
operator int&() { return value; }
};
struct Derived : Base {
operator int() { return operator int&(); }
private:
using Base::operator int&;
};
int main() {
int p = Derived();
}
P.S. The compiler uses gcc 9.3.0, and the real case is the wrapping of XmlRpc::XmlRpcValue class from ROS to handle probable conversion from double XmlRpcValue type to int or int XmlRpcValue type to double.