Answered step by step
Verified Expert Solution
Question
1 Approved Answer
C++. Thanks 7. Answer the parts of this question with consideration to the following user-defined type definitions struct Coord2D struct Coord3D public Coord2D [ double
C++. Thanks
7. Answer the parts of this question with consideration to the following user-defined type definitions struct Coord2D struct Coord3D public Coord2D [ double x; double y; double z; J: Slicing occurs when an object of a derived class (Coord3D) is assigned to, or is used to initialize, an instance of a base class (Coord2D). You can think of slicing as the class object equivalent of integer truncation (a) Draw a diagram that shows how the objects c2d and c3d are laid out in memory after the following code is executed: Coord3D c3d; c3d.x - 12.1; c3d.y-13.1; c3d.z- 32.2; Coord2D c2d c3d; (b) You might think that the following code will result in c3dA being a copy of c3dB after its execution. Instead, the data members of c3dA will store some combination of the original data and those values stored in c3dB. Why is this the case? Coord3D c3dA; c3dA.x - 1; c3dA.y - 2; c3dA.z -3; Coord3D c3dB; c3dB.x - 11; c3d.y - 12; c3d.z -13; Coord2D &c2dref F c3dA; c2d_ref F C3dB; (c) It follows from the previous part that class hierarchies plus pass-by-reference and default copying do not mix. It is recommended that when you design a class that is meant to be a base class in a hierarchy, you should disable its copy constructor and copy assignment operator. How could go about doing this (d) What happens if we define an abstract class and then try to define an object of that typeStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started