I have the following operator defined in a C++ class called StringProxy:
operator std::string&()
{
return m_string;
}
a) What is this and how does this work? I understand the idea of operator overloading, but they normally look like X operator+(double i).
b) Given an instance of StringProxy, how can I use this operator to get the m_string?
This is a conversion method. To get the m_string, simply use an explicit cast:
(std::string)stringProxyto perform the conversion. Depending on context (e.g. if you’re assigning to a string), you may be able to do without the cast.