Hello every one
I have some questions about the delete function in this following code.


Code:
   1 #include <iostream> 
   2 #include <cstring> 
   3 using namespace std; 
   4  
   5 class String 
   6 { 
   7 private: 
   8         char *string; 
   9         long len; 
  10 public: 
  11         String (); 
  12         String (const char *I_string); 
  13         String & operator = (const String &); 
  14         void show_data () const; 
  15         ~String (); 
  16 }; 
  17  
  18 String::String () 
  19 { 
  20         len=0; 
  21         string=new char [len+1]; 
  22         string='\0'; 
  23 } 
  24  
  25 String::String (const char *I_string) : len(strlen(I_string)) 
  26 { 
  27         string=new char [len+1]; 
  28         strcpy(string,I_string); 
  29 } 
  30  
  31 String & String::operator = (const String & astring) 
  32 { 
  33         delete [] string; 
  34         string=new char [astring.len+1]; 
  35         strcpy(string,astring.string); 
  36         return * this; 
  37 } 
  38  
  39 void String::show_data () const 
  40 { 
  41         cout << "the string is : " << string <<endl; 
  42         cout << "the address is : " << (void *) string << endl; 
  43 } 
  44  
  45 String::~String () 
  46 { 
  47         delete [] string; 
  48 } 
  49 int main () 
  50 { 
  51         String A_string ("my string"); 
  52         String B_string; 
  53  
  54         B_string=A_string; 
  55  
  56         A_string.show_data (); 
  57         B_string.show_data (); 
  58  
  59         return 0; 
  60 }


As shown in the code, it has two objects: A_string and B_string. It uses delete function at line 33 and line 47 to free the memory of string. My question is the delete function at line 33 will free the memory of string which belongs to B_string or the string's memory of A_string and B_string at the same time. I also have the same puzzle at line 47. who can explain them for me.


Thanks
fan li