Consider the code below. I don't understand why my GCC compiler does not try to implicitly use Myclass::operator string(), although Myclass::operator string() is defined:
#include <string>
using namespace std;
struct T {
};
T operator+(const T& a, const T&b) { }
struct Myclass {
    operator string() const { }
    operator T() const { }
};
int main() {
    T a;
    string b;
    Myclass c;
    c + a;  // OK
    c.operator  string() + b; // OK
    c + b; // Not OK
    /* The above line does not compile, although in <string> I see:
    basic_string<_CharT, _Traits, _Alloc>
    operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
          const basic_string<_CharT, _Traits, _Alloc>& __rhs)
     */
}
                Because the string operator is a template, it cannot be picked up whereas the other operator can.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With