// string1.h -- fixed and augmented string class definition
#include <iostream>
using std::ostream;
using std::istream;
#ifndef STRING1_H_
#define STRING1_H_
class String
{
private:
char * str; // pointer to string
int len; // length of string
staticint num_strings; // number of objects
staticconstint CINLIM = 80; // cin input limit
public:
// constructors and other methods
String(constchar * s); // constructor
String(); // default constructor
String(const String &); // copy constructor
~String(); // destructor
int length () const { return len; }
void stringlow();
void stringup();
int has(char c) const;
// overloaded operator methods
String & operator=(const String &);
String & operator=(constchar *);
char & operator[](int i);
constchar & operator[](int i) const;
// overloaded operator friends
friendbooloperator<(const String &st, const String &st2);
friendbooloperator>(const String &st1, const String &st2);
friendbooloperator==(const String &st, const String &st2);
friend ostream & operator<<(ostream & os, const String & st);
friend istream & operator>>(istream & is, String & st);
friendconst String operator+(const String& st1, const String& st2);
// static function
staticint HowMany();
};
#endif
This is the definition of the overloaded + operator, where I must use new to allocate the memory. However, there seems no place I can use a delete to free the memory pointed by ps.