1. virtual bool equal(const Object* other_object) { return (id == other_object->id); } //at objects.h
  2.  
  3. //at object.cpp:
  4. bool String::equal(const Object* other_object)
  5. {
  6.     cout <<"the_string: " << endl;
  7.     //this->print();
  8.     cout << this->get_string() << endl;
  9.     cout <<"other_object the_string: " << endl;
  10.     //cout << dynamic_cast<String*>(other_object)->get_string() << endl;
  11.     //cout << ((String*)other_object)->get_string() << endl;
  12.     //cout << ((String*)other_object)->the_string << endl; --> also this line prints garbage
  13.     //((PassengerCompartment*)other_object)->get_description().print();
  14.     //check if strings are the same
  15.     if ( the_string == ((String*)other_object)->the_string)
  16.     {
  17.         //check id
  18.         if ( Object::equal(other_object) )
  19.             return true;
  20.         else
  21.             return false;
  22.     }
  23.     else
  24.         return false;
  25. }
  26.  
  27.  
  28. ////////////////////////////////////////////
  29. bool PlaneComponent::equal(const Object* other_object)
  30. {
  31.     cout << "------------------" << endl;
  32.     cout << "------------------" << endl;
  33.     cout << "------------------" << endl;
  34.     cout << "------------------" << endl;
  35.     cout << "--------PlaneComponent::equal----------" << endl;
  36.     this->get_description().print();
  37.     ((PassengerCompartment*) other_object)->get_description().print(); //is printed correctly!
  38.     cout << "--------PlaneComponent::equal----------" << endl;
  39.     cout << "------------------" << endl;
  40.     cout << "------------------" << endl;
  41.     cout << "------------------" << endl;
  42.     cout << "------------------" << endl;
  43.     //check if description is the same
  44.     if ( description.equal(other_object) )
  45.     {
  46.         //check id
  47.         if ( Object::equal(other_object) )
  48.             return true;
  49.         else
  50.             return false;
  51.     }
  52. }
  53.  
  54. bool PassengerCompartment::equal(const Object* other_object)
  55. {
  56.     bool result = false;
  57.     //if there is an inner compartment check if equal
  58.     if ( inner_PassengerCompartment != NULL ) ////to simplify the problem I create a
  59.                           ////NULL inner_PassengerCompartment
  60.                           ////so this block is not "active"
  61.     {   //manually check for it's description and ID to avoid recursion
  62.         if ( get_description() == ((PlaneComponent*)other_object)->get_description() )
  63.         {   //check IDs
  64.             if ( get_id() == other_object->get_id() )
  65.                     result = true;
  66.             else    result = false;
  67.         }
  68.         else result = false;
  69.         if ( inner_PassengerCompartment->PlaneComponent::equal( ((PassengerCompartment*)other_object)->inner_PassengerCompartment ) )
  70.                 result = true;
  71.         else    result = false;
  72.     }
  73.  
  74.     //all the printing done below is correct!!
  75.     this->get_description().print();
  76.     ((PassengerCompartment*) other_object)->get_description().print();
  77.  
  78.     //check for the passenger compartment itself
  79.     if ( PlaneComponent::equal(other_object) )
  80.             result = true;
  81.     else    result = false;
  82.    
  83. }
  84.  
  85.  
  86.  
  87. ///////////////////////////////////////////////////////////////////////////////
  88. ///////////////////////////////COPY CONSTRUCTORS///////////////////////////////
  89. ///////////////////////////////COPY CONSTRUCTORS///////////////////////////////
  90. ///////////////////////////////////////////////////////////////////////////////
  91.  
  92. Object::Object(const Object& object_)
  93. {
  94.     id = object_.id;
  95.     cout << "Copy of Object just created!" << endl;
  96. }
  97.  
  98.  
  99. String::String(const String& given) : Object(given)
  100. {
  101.     the_string = given.the_string;
  102.     cout << "Copy of String just created!" << endl;
  103. }
  104.  
  105.  
  106. PlaneComponent::PlaneComponent(const PlaneComponent& given) : Object(given), description(given.description)
  107. {
  108.     cout << description.get_string() << endl;
  109.     cout << "PlaneComponent just created!" << endl;
  110. }
  111.  
  112.  
  113. PassengerCompartment::PassengerCompartment(const PassengerCompartment& given) : PlaneComponent(given)
  114. {
  115.     if (given.inner_PassengerCompartment != NULL )
  116.     {//if the given PassengerCompartment has an inner PassengerCompartment, copy that, too
  117.         inner_PassengerCompartment = new PassengerCompartment(*(given.inner_PassengerCompartment), true);
  118.         std::cout << "Inner PassengerCompartment just created!" << std::endl;
  119.     }
  120.     else
  121.         inner_PassengerCompartment = NULL;
  122.     std::cout << "PassengerCompartment just created!" << std::endl;
  123. }
  124.  
  125.  
  126. PassengerCompartment::PassengerCompartment(const PassengerCompartment& given, bool for_innerPC) : PlaneComponent(given)
  127. {   //////this is done for the simplification of the problem
  128.     inner_PassengerCompartment = NULL;
  129. }