// File: astring2.C // // Implementation of a silly string class #include #include #include #include #include "astring2.h" AString::AString() { str = NULL ; length = -1 ; } AString::AString(const char * s) { length = -1 ; if (s == NULL) { str = NULL ; return ; } str = strdup(s) ; if (str == NULL) { cerr << "Oops" << endl ; exit(1) ; } } AString::AString(const AString& as) { length = -1 ; if (as.str == NULL){ str = NULL ; return ; } length = as.len() ; str = strdup(as.str) ; if (str == NULL) { cerr << "Oops" << endl ; exit(1) ; } } int AString::len() const { if (length >= 0) return length ; if (str == NULL) { length = 0 ; return 0 ; } length = strlen(str) ; return length ; }