12345678910111213141516171819202122
class String { private: char *ptr; public: String(); String(char *s); String(const String &src); String cti(const String &src) {return atoi();} ~String(); String& operator=(const String &src) {cpy(src.ptr); return *this;} String& operator=(char *s) {cpy(s); return *this;} String operator+(char *s); operator char*() {return ptr; } int operator==(const String &other); bool operator<(const String &other); bool operator>(const String &other); void cat(char *s); void cpy(char *s); };
int cti() {return atoi(ptr);}
int cti() const {return (ptr != 0) ? atoi(ptr) : 0;}
1234
char c_str[] = "123"; // This because in String it is 'char *' and not 'const char *' String s(c_str); // c_str may be modified at this point? ... int x = s.cti(); // x is 123