Use original work!! or will downvote* INSTRUCTIONS: In this assignment, you will make your own smart pointer type. You will write the following class to develop a referenced counted smart pointer. You will also implement a few other member functions to resemble the functionality of an ordinary raw pointer. Basically, this is a problem of designing a single, non-trivial class and overloading a few pointer related operators. You may not use any of the STLs except for stdexcept, to do this, i.e., please dont try and use a shared_ptr to implement the class. You can start with this code, and you may add other member functions, if you want.
*Use original work!! or will downvote*
INSTRUCTIONS: In this assignment, you will make your own smart pointer type. You will write the following class to develop a referenced counted smart pointer. You will also implement a few other member functions to resemble the functionality of an ordinary raw pointer. Basically, this is a problem of designing a single, non-trivial class and overloading a few pointer related operators. You may not use any of the STLs except for stdexcept, to do this, i.e., please dont try and use a shared_ptr to implement the class. You can start with this code, and you may add other member functions, if you want.
C++ LANGUAGE
Only need smart_ptr.h file.
*Use original work!! or will downvote*
![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. Make sure it points to
// the same pointer as the raw_ptr.
smart_ptr(const smart_ptr& rhs);
// Copy construct a pointer from rhs. The reference count
// should be incremented by one.
smart_ptr(smart_ptr&& rhs);
// Move construct a pointer from rhs.
smart_ptr& operator=(const smart_ptr& rhs);
// This assignment should make a shallow copy of the
// right-hand side's pointer data. The reference count
// should be incremented as appropriate.
smart_ptr& operator=(smart_ptr&& rhs);
// This move assignment should steal the right-hand side's
// pointer data.
bool clone();
// If the smart_ptr is either nullptr or has a reference
// count of one, this function will do nothing and return
// false. Otherwise, the referred to object's reference
// count will be decreased and a new deep copy of the
// object will be created. This new copy will be the
// object that this smart_ptr points and its reference
// count will be one.
int ref_count() const;
// Returns the reference count of the pointed to data.
T& operator* ( );
// The dereference operator shall return a reference to
// the referred object. Throws null_ptr_exception on
// invalid access.
T* operator->();
// The arrow operator shall return the pointer ptr_.
// Throws null_ptr_exception on invalid access.
~smart_ptr(); // deallocate all dynamic memory
private:
T* ptr_; // pointer to the referred object
int* ref_; // pointer to a reference count
};](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Ff3262043-d0f4-48ea-9e96-21670a135aa2%2F25b815b3-1572-4235-92a6-f7d591c9cf4b%2F7uriebo_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![C++ Programming: From Problem Analysis to Program…](https://www.bartleby.com/isbn_cover_images/9781337102087/9781337102087_smallCoverImage.gif)
![C++ Programming: From Problem Analysis to Program…](https://www.bartleby.com/isbn_cover_images/9781337102087/9781337102087_smallCoverImage.gif)