Question: (b) The class modelling a node in a family tree is given in Listing 4 . class FamilyTreeNode { public: I/ public member functions including

 (b) The class modelling a node in a family tree is

(b) The class modelling a node in a family tree is given in Listing 4 . class FamilyTreeNode \{ public: I/ public member functions including a copy constructor and assignment operator void swap(FamilyTreeNodes rhs); private: shared_ptrepersons - mother: shared_ptrePersons father; Person_person; Listing 4: FamilyTreeNode class A fellow student has written a copy constructor and assignment operator for this class and you have been asked to review their code. You notice the following: - The copy constructor has been written correctly to create independent copies of FamilyTreenode objects. - The student is using the canonical form of the assignment operator. - Their version of the FamilyTreeNode: : swap function is: void FamilyTreeNode: : swap (FamilyTreeNode\& rhs) \{ -mother, swap (rhs,_mother); -father, swap(rhs. _father); 5wap (_person, rhs._person); \} which makes use of the standalone swap function which is defined as follows: template void swap(T\& a,T& b) T temp(a); a=b; b= temp; \} Answer the following questions relating to the above scenario. i. Give the canonical form of the assignment operator. (2 marks ii. The student has not implemented assignment correctly for the FamilyTreeNode class. Explain how the implementation is flawed and provide any necessary modi fications to the classes involved to correct the flaw. Note, the assignment operato: for the FamilyT reeNode class must still follow the canonical form. (6 marks

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!