/* yada yada yada... */
class String
{
private:
char* charList;
int size;
public:
String ();
String (String& s);
~String ();
/* yada yada yada... */
void operator= (String s);
/* yada yada yada... */
};
/* yada yada yada...*/
/*
Creates an empty String
*/
String::String ()
{
size = 0;
}
/*
Creates a copy of another String object.
*/
String::String (String& s)
{
this->size = s.size;
charList = new char[size];
for (int i = 0; i < size; i++)
{
charList = s.charList;
}
}
/*
String Destructor. Liberates allocated memory.
*/
String::~String ()
{
delete charList;
}
/* yada yada yada…*/
/*
Assignment operator. Sets a String equal to the given String.
*/</font>
<font color="blue">void</font> String::operator= (String& s)
{
size = s.size;
<font color="blue">delete</font> charList;
charList = <font color="blue">new</font> char[<font color="purple">size</font>];
<font color="blue">for</font> (<font color="blue">int</font> i = 0; i < size; i++)
{
cout << <font color="darkred">"s.charList[<font color="purple">"</font> << i << <font color="darkred">"</font>] = "</font> << s.charList[<font color="purple">i</font>];
charList[<font color="purple">i</font>] = s.charList[<font color="purple">i</font>];
}
}
</pre></DIV><!–ENDSCRIPT–>
If you need any more info to help me, don't hesitate to ask.
vv Edit Notice vv
<SPAN CLASS=editedby>[edited by - Tac-Tics on May 13, 2002 7:32:39 PM]</SPAN>