Design and implement a counted_ptr that is a type that holds a pointer to an object of
Question:
Design and implement a counted_ptr that is a type that holds a pointer to an object of type T and a pointer to a “use count” (an int) shared by all counted pointers to the same object of type T. The use count should hold the number of counted pointers pointing to a given T. Let the counted_ptr’s constructor allocate a T object and a use count on the free store. Let counted_ptr’s constructor take an argument to be used as the initial value of the T elements. When the last counted_ptr for a T is destroyed, counted_ptr’s destructor should delete the T. Give the counted_ptr operations that allow us to use it as a pointer. This is an example of a “smart pointer” used to ensure that an object doesn’t get destroyed until after its last user has stopped using it. Write a set of test cases for counted_ptr using it as an argument in calls, container elements, etc.
Step by Step Answer:
Here is an example of how the countedptr class could be ...View the full answer
Students also viewed these Computer science questions
-
Design an MPC controller for the reactor/flash unit plant and test it using a simulation of the linearized model of this plant. For purposes of this exercise, first design and implement a PI...
-
Design and implement a C++ class called Module that handles information regarding your assignments for a specific module. Think of all the things you would want to do with such a class and write...
-
Design the door class which has the property of either open or shut. The door can also be opened and shut. Design another special type of door class called lockable door. Lockable door is like a...
-
Find steady state current i of a RL circuit with L=2 H and R=892 which can be modeled by the following differential equation: 2di/dt+8i=v(t) where v(t) = 16 cos(10t -45) with phasor technique. Also...
-
What has happened to wage inequality since 1980? What factors account for this change?
-
Planning and flexible budget variances Tang Company??s production performance report for April includes the information shown below. Prepare a flexible budget for the items shown and compute the...
-
List three profitability ratios and discuss how these ratios are used to assess a company's performance.
-
Inglis City had a beginning cash balance in its enterprise fund of $895,635. During 2014, the following transactions occurred: 1. Interest received on investments totaled $42,400. 2. The city...
-
Select from the option list provided the most appropriate response to each item related to fund accounting and reporting. Item Type 1. Resources most likely accounted for by a special revenue fund....
-
Pin B has a mass m and slides along the slot in the rotating arm OC and along the slot DE which is cut in a fixed horizontal plate. Neglecting friction and knowing that rod OC rotates at the constant...
-
What is a template?
-
What are the two most useful types of template arguments?
-
In the network in figure, the switch opens at t = 0. Use Laplace transforms to find i(t) for t >0. 3H 330 12 v (+ i(t)
-
The following are selected transactions for Jefferson, Inc., during the month of April: 27 Lind Stores returned defective merchandise billed at \(\$ 300\) on April 20. 29 Received from Lind Stores a...
-
The following legal situations apply to Stringer Corp. for 2011: 1. A customer slipped and fell on a slick floor while shopping in the retail store. The customer has filed a \(\$ 5\) million lawsuit...
-
Identifying if an economy is in medium run equilibrium and the necessary central bank action to return the economy to medium run equilibrium Here are values for a hypothetical economy \(Y_{n}=1000 ;...
-
From the following network data, determine the critical path, early start, early finish, late start, late finish, TF, and FF for each activity. Highlight the critical path. 05 NC 1 F TI NX 2 I + 3 B...
-
Kiwi Kapers Limited (KKL) is a New Zealand-based manufacturer and retailer of sports clothing with headquarters in Dunedin. Although its manufacturing facilities are all located in Dunedin, its...
-
This year, John, Meg, and Karen form Frost Corporation. John contributes land purchased as an investment four years ago for $25,000 that has a $30,000 FMV in exchange for 30 shares of Frost stock....
-
How can a promoter avoid personal liability for pre-incorporation contracts?
-
What is the maximum size of the TCP header? What is the minimum size of the TCP header?
-
An HTTP client opens a TCP connection using an initial sequence number (ISN) of 14,534 and the ephemeral port number of 59,100. The server opens the connection with an ISN of 21,732. Show the three...
-
In TCP, does a SYN segment open a connection in only one direction or in both directions?
-
Exercise 21-5 (Algo) Preparing flexible budget performance report LO P1 Nina Company prepared the following fixed budget for July using 7,560 units for budgeted sales. Actual sales were 7,260 units...
-
Lab Objectives 0 Use methods ofthe Character class and String class to process text 0 Be able to use the String . spl it method and the StringBuilder class Introduction In this lab we ask the user to...
-
. Menlo Company distributes a single product. The company's sales and expenses for last month follow: Total Per Unit Sales $ 450,000 $ 30 Variable expenses 180, 000 12 Contribution margin 270,000...
Study smarter with the SolutionInn App