| 
      
         
            CMPT 212 
         
            Spring 1998
         
       | 
   
   sentence first = oldSentence;      //  These two lines do the
   sentence first(oldSentence);       //  same thing.
               
            
            but it does not solve this one:
            
               
   sentence first;
   first = oldSentence;      //  Initialize an existing instance.       
               
            
            For this we need operator overloading.
      
   const sentence& sentence::operator=(const sentence& s) {
      if (this != &s) {
         delete [] words;
         words = new char[strlen(s.words) + 1];
         strcpy(words, s.words);
         count = s.count;
         }
      return *this;
   }
         
      
   
         
             
            Return to lecture notes index  | 
      
         
  | 
   
| This page is maintained by simpson@cs.sfu.ca. | Last updated on 18 Feb 1998. |