E
ES Kim
Consider:
#include <string>
#include <iostream>
using namespace std;
struct S
{
const char* ps_;
operator string();
};
int main()
{
S s;
cout << s;
}
operator<<(ostream&, const string&) is defined in the standard and
the conversion from S to string is, too. But compilers reject this code
since operator<<(ostream&, const S&) is not defined.
What's wrong with this code?
#include <string>
#include <iostream>
using namespace std;
struct S
{
const char* ps_;
operator string();
};
int main()
{
S s;
cout << s;
}
operator<<(ostream&, const string&) is defined in the standard and
the conversion from S to string is, too. But compilers reject this code
since operator<<(ostream&, const S&) is not defined.
What's wrong with this code?