// File: HLtest3.cpp // // Testing copy constructor & destructor // #include #include "HList.h" #include "IntNode.h" #include "DoubleNode.h" #include "StringNode.h" using namespace std ; HList foo(HList L3) { HNode *ptr ; StringNode *sptr ; IntNode *iptr ; cerr << "\n\n Entering foo():\n\n" ; ptr = L3.find(StringNode("World")) ; sptr = dynamic_cast(ptr) ; if (sptr == 0) cout << "Dynamic cast failed!!\n" ; sptr->set("New York") ; ptr = L3.find(IntNode(7) ) ; iptr = dynamic_cast(ptr) ; if (iptr == 0) cout << "Dynamic cast failed!!\n" ; iptr->set(17) ; cout << "In foo(), L3 = " << L3 << "\n\n" ; cerr << "\n\n Exiting foo():\n\n" ; return L3 ; } int main() { HList L1, L2; L1.push_front(new IntNode(9)) ; L1.push_front(new StringNode("World")) ; L1.push_front(new IntNode(8)) ; L1.push_front(new IntNode(7)) ; L1.push_front(new StringNode("Hello")) ; L1.push_front(new IntNode(6)) ; L1.push_front(new DoubleNode(3.14157926)) ; L1.push_front(new DoubleNode(2.78)) ; cout << "In main(), L1 = " << L1 << "\n\n" ; L2 = foo(L1) ; cout << "In main(), L1 = " << L1 << "\n\n" ; cout << "In main(), L2 = " << L2 << "\n\n" ; }