Question

Hi all, I need help to do a project based on C++ smart pointers. I have...

Hi all,

I need help to do a project based on C++ smart pointers. I have to implement the class template my_unique_ptr which is a pointer management class template. Also, it's required to implement the following public methods:

a. Default constructor that initializes the object to point to nullptr.

b. Constructor that takes a pointer Type * as a parameter and sets the object to point there. We say that the newly created object takes ownership of the pointed memory.

c. Move constructor that takes my_unique_ptr object and constructs a new object from it.

d. Copy constructor should be explicitly disabled/deleted !!!

e. Destructor that releases/deletes the block of memory pointed by the object.

f. Dereference operator * that returns a reference to the item pointed by the object.

g. Operator -> that returns the pointer to the object. It allows to use the my_unique_ptr object for class member access.

h. Move assignment operator.

i. Copy assignment operator must be explicitly disabled/deleted !!!

j. method isNullptr() that returns true if the pointer points to nullptr and false otherwise. This operator will help us to write tests.

0 0
Add a comment Improve this question Transcribed image text
Know the answer?
Add Answer to:
Hi all, I need help to do a project based on C++ smart pointers. I have...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Code in c++ please. Does not have to be complete, just write code for the ones you know. Thank y...

    Code in c++ please. Does not have to be complete, just write code for the ones you know. Thank you. template <typename T> class smart_ptr { public: smart_ptr(); // Create a smart_ptr that is initialized to nullptr. The reference count // should be initialized to nullptr. explicit smart_ptr(T* raw_ptr); // Create a smart_ptr that is initialized to raw_ptr. The reference count // should be one. smart_ptr(const smart_ptr& rhs); // Copy construct a pointer from rhs. The reference count should be...

  • I do not understand the output when using dog.print() Can you explain what happens when Dogtype...

    I do not understand the output when using dog.print() Can you explain what happens when Dogtype dog("Tommy", "German....."); and dog.print() executes. This is c++ For classes 1. Include the destruc 2. 3. Include the copy constructor. tor in lI Overload the assignment operator for the class r 13 discusses overloading the assignment operator. Until Chapte discuss classes with pointer member variables, out of the three iten we will implement only the destructor and the copy constructor. Inheritance, Pointers, and Virtual...

  • // thanks for helping // C++ homework // The homework is to complete below in the...

    // thanks for helping // C++ homework // The homework is to complete below in the stack.h : // 1. the copy constructor // 2. the assignment operator // 3. the destructor // 4. Write a test program (mytest.cpp) to test copy and assignment // 5. Verify destructor by running the test program in Valgrind // This is the main.cpp #include <iostream> #include "stack.h" using namespace std; int main() { Stack<int> intStack; cout << "\nPush integers on stack and dump...

  • In C++ and comment so I UNDERSTAND Implement a class named DynamicArray that has the following...

    In C++ and comment so I UNDERSTAND Implement a class named DynamicArray that has the following members: A pointer to hold a dynamically allocated array, of type int. A member variable to hold the size of the array. A default constructor, which will allocate an array of size 10 A parameterized constructor, which takes a size and use the size to allocate array. A copy constructor, which performs deep copy. A copy assignment operator, which performs deep copy and supports...

  • In C++ Create a class called MyInteger. It should have a field of type pointer-to-int called...

    In C++ Create a class called MyInteger. It should have a field of type pointer-to-int called pInteger. It should have a constructor that takes as a parameter an int - the constructor will then dynamically allocate memory for an int, using pInteger, and assign the parameter's value to that memory. The class should have a destructor that will deallocate that memory when the object is destroyed. You should write a copy constructor that will correctly make a separate copy of...

  • This is a c++ class utilizing class templates and linked lists. I need to implement the...

    This is a c++ class utilizing class templates and linked lists. I need to implement the following member function(s) to List.cpp. Node.hpp/cpp should be fine but if you feel like there needs to be a change for compilation or testing, feel free to do so but make sure to comment on why it was done. /** @pre assumes position is valid, if position is > item_count_ it returns an empty List, also assumes that operators <= and >= are defined...

  • please write in c++. 4 Derived class JPG 4.1 Class declaration • The class JPG inherits...

    please write in c++. 4 Derived class JPG 4.1 Class declaration • The class JPG inherits from File and is a non-abstract class. 1. Hence objects of the class JPG can be instantiated. 2. To do so, we must override the pure virtual function clone() in the base class. • The class declaration is given below. class JPG : public File { public: JPG(const std::string& n, int n, int w, const double rgb()) : File(...) { // ... } *JPG()...

  • please write the code in C++ 2 Base class File 3 Derived class PDF 3.1 Class...

    please write the code in C++ 2 Base class File 3 Derived class PDF 3.1 Class declaration • The class PDF inherits from File and is a non-abstract class 1. Hence objects of the class PDF can be instantiated. 2. To do so, we must override the pure virtual function clone) in the base class • The class declaration is given below. • The complete class declaration is given below, copy and paste it into your file. . It is...

  • C++,please help. I have no idea how to do that begining with zero parameter constructor. and...

    C++,please help. I have no idea how to do that begining with zero parameter constructor. and help me to test the method, Write a class template Square Matrix that implements a square matrix of elements of a specified type. The class template should be fully in the Square Matrix.h file. The class uses "raw" pointers to handle the dynamically allocated 2D-array. "Raw" pointers are the classic pointers that you've used before. In addition to it, you will need a variable...

  • Objective: In this assignment you will do the following: (1) manipulate pointers, (2) allocate me...

    Objective: In this assignment you will do the following: (1) manipulate pointers, (2) allocate memory dynamically, (3) implement a default constructor, copy constructor and destructor, (4) use only one pointer to add to the back and to dequeue from the front of the queue. Assignment Description: You will implement a doubly-linked circular queue of integers. Consider the following class declarations when implementing BQUEUE. As always, you must comment your declaration and implementation files, "BQUEUE.h" and "BQUEUE.cpp", respectively. class bqnode {...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT