Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Base.h* + X Lab8AbstractBaseClasses.cpp* Base.cpp* + X v Lab - Abstract Base Classes Q #+ Lab8AbstractBaseClasses Base + Lab8AbstractBaseClasses Base Base(const Base & other) #pragmaonce

image text in transcribed
Base.h* + X Lab8AbstractBaseClasses.cpp* Base.cpp* + X v Lab - Abstract Base Classes Q #+ Lab8AbstractBaseClasses Base + Lab8AbstractBaseClasses Base Base(const Base & other) #pragmaonce #include "Base.h" #include OVERVIEW COMPLETION FEEDBACK avoid Base: : SetName(char* name) class Base OCO NAMEWNA if (_name != nullptr) private: Base.h/cpp char* _name = nullptr; delete _name; 8 Create a Base class. Add a private char* member to 9 int length = strlen(name) + 1; 10 public: 10 _name = new char[length] ; the class for the name and initialize it to nullptr. 11 void SetName(char* name) ; 11 strcpy_s(_name, length, name) ; 12 char* GetName(); 12 Next, implement a public SetName method (it must 13 13 do a deep copy of the memory since the name is a 14 virtual void DisplayRecord() = 0; 14 char* Base: : GetName() 15 15 dynamic pointer). You may use the CopyString 16 / /DEFAULT CONSTRUCTOR 16 return _name; 17 Baco(). 17 method from lecture. Also add a public GetName() 18 class Base 18 19 /DESTRUCTOR 19 method that will return the name. + Base: : Base() 20 ~Base(); 20 21 21 Declare a public DisplayRecord method that is pure 22 / /COPY CONSTRUCTOR 22 23 - - . . . . .. . . . ... ........... Base(const Base& other); 23 Base: : ~Base() virtual (meaning it will have no definition): 24 25 / /ASSIGNMENT OPERATOR 25 delete _name; virtual void DisplayRecord() = 0; 26 Based operator=(const Base& other) ; 26 27 27 Finally, fully implement the Rule of 3 for the class 28 13i 28 Base: : Base(const Base& other) 29 29 because it has a dynamic memory member. 30 *this = other; 31 HINT: You only need to write the operator= and just 32 33 have your copy constructor call that method (*this = Bases Base: :operator=(const Bases other) 34 copy;) since they will usually have the same code. 35 // TODO: insert return statement here 36 37 Because the rule of 3 incorporates a copy constructor, you will lose the blank default constructor that Visual Studio writes for you. Add an empty default constructor to the class to fix this

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

=+ Documenting datasets using datasheets to

Answered: 1 week ago

Question

What is a CAFR? What are its main components?

Answered: 1 week ago