class String {
public:
String(constchar *value); // see Item 11 for pos-
~String(); // sible implementations;
// see Item M5 for comments
// on the first constructor
operatorchar *() const; // convert String -> char*;
// see also Item M5
...
private:
char *data;
};
const String B("Hello World"); // B is a const object
char *str = B; // calls B.operator char*()
Isn't argument needed for the operator function, so it can decide what to convert?
Well other operators are declared this way: ReturnType operator Symbol ( arguments );
Conversion operator is declared this way: operator DataType ( void );
Because the DataType is the return type and you don't need arguments