Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

(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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Case Studies In Business Data Bases

Authors: James Bradley

1st Edition

0030141346, 978-0030141348

More Books

Students also viewed these Databases questions