Question: c++ smart pointer Begin by creating the class definition for UniquePtr shown below in a header file named UniquePtr.h. This version of UniquePtr is designed

c++ smart pointer

c++ smart pointer Begin by creating the class definition for UniquePtr shownbelow in a header file named UniquePtr.h. This version of UniquePtr is

Begin by creating the class definition for UniquePtr shown below in a header file named UniquePtr.h. This version of UniquePtr is designed to wrap a pointer to an object of type Foo ; you should find the source code defining the Foo class ( Foo.h and Foo. epp) in the Resources section of this assignment. class UniquePtrt public: UniquePtr (Foo* ptr) UniquePtr); protected: Foo* ptr NOTE: Place both the class definition and method implementations in the header file. You need not write all your method definitions directly in the class definition; you can place them below. The reason to keep everything in one header file is that you will be converting your class to a template later in this lab; all template code must reside in a header file Constructor The constructor takes an owning pointer to a Foo object; the UniquePtr l asume ownership of that object, saving the pointer in its _ptr attribute. The expectation is that the UniquePtr ll be constructed directly with the result of a new operation, as in the following: UniquePtr fooPtr(new Foo; Implement the constructor now. The destructor will destroy the object that is being managed by the smart pointer. Implement the destructor now. Test Add code to a driver program that will test your ability to construct and destruct your smart pointer Hint: You can use braces to create small sections of scope for the purpose of testing how objects behave when they go out of scope within the context of a running program. See example below: std::cout

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!