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?
-
Some companies use production learning curves to set pricing strategies. They price their product lower than the initial cost of making the product; after some period of time, the learning curve...
-
Consider a $2^{3}$ experiment with factors A, B, and C. Show that \[\begin{aligned}I N T(A, B, C) & =\frac{1}{2}[I N T(A, C \mid B+)-I N T(A, C \mid B-)] \\& =\frac{1}{2}[I N T(C, B \mid A+)-I N T(C,...
-
Qamar, Inc., did not pay dividends in 2009 or 2010, even though 50,000 shares of its 6.5%, $50 par value cumulative preferred stock were outstanding during those years. The company has 800,000 shares...
-
Q3. Consider the expression below. (3) + (27) -2 Explain the mathematical properties you would use to simplify this expression into the form 3" and describe the process to find the value of a. A...
-
Allie has bought a new apple orchard. The orchard has a single file of trees, numbered from 1 to N. Each tree has a certail number of ripe apples. Allie has a rule she wants to follow. She wants to...
-
What is a template?
-
What are the two most useful types of template arguments?
-
A stock has had returns of 6 percent, 29 percent, 13 percent, 19 percent, 34 percent, and 2 percent over the last six years. What are the arithmetic and geometric average returns for the stock?
-
4 Find f'(x) for f(x) = = In(x2) f'(x) = Preview
-
A department store offers the following credit terms on a new appliance "slashed" to a price of $300: only $100 down, and the balance in 24 monthly installments of $12.50. What monthly rate of...
-
An employee starts work on 1 January 2000 on an annual salary of $30,000. His pay scale will give him an increase of $800 per annum on the first of January until 1 January 2015 inclusive. He remains...
-
1a. For the function f(x) = x 3x 9x, find the intervals where it is increasing, the intervals where it is decreasing, the local maxima and the local minima.
-
Vella owns and operates an illegal gambling establishment. In connection with this activity, he has the following expenses during the year: Rent: $24,000 Bribes: $40,000 Travel expenses: $4,000...
-
Use the New Design Ltd. data from Problem 17-3B. Required 1. Prepare the 2014 cash flow statement by the indirect method. If your instructor also assigned Problem 17-3B, prepare only the operating...
-
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?
-
Give a brief description of a product launch for any business firm/organization that you want to open or would want to work with in future. Provide at least two appropriate 'Call to Actions' for the...
-
Briefly explain the organizational pattern of a 'Feature Article'? Why is 'tension' so important in a Feature article?
-
Cemex has an enviable past, a struggling present and an uncertain future. The company boasts of a century-old history and has weathered many a storm in an unfriendly Mexican business environment....
Study smarter with the SolutionInn App