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?
-
Genes Q, R, and S are on the same chromosome. The crossover frequency between S and Q is 5%, the crossover frequency between Q and R is 30%, and the crossover frequency between R and S is 35%. Use...
-
A probability experiment consists of tossing a coin and spinning the spinner shown at the left. The spinner is equally likely to land on each number. Use a tree diagram to find the probability of...
-
Dewitt Industries has adopted the following production budget for the first 4 months of 2012. Each unit requires 3 pounds of raw materials costing $2 per pound. On December 31, 2011, the ending raw...
-
1/ True, False or Uncertain? Justify your response to the following statements. a) Consider the new residential development in north Toronto. A 1300 sq. ft. house was recently sold for $600,000. The...
-
Stub Hub is a popular Web site where fans can buy and sell tickets to concerts and sporting events. Below are data representing the amounts (in dollars) that buyers using StubHub spent on Super Bowl...
-
What is a template?
-
What are the two most useful types of template arguments?
-
Julius Brooks, plant manager for ICL, Inc., a manufacturer of auto parts, has been successful in recent years because of the very high quality of his products and the speed of delivery. A growing...
-
In 1969, a radical new childrens program appeared on television, one specifically designed to blend education with entertainment (characterproducts.com, 2004). Sesame Street, which has been on the...
-
Dolly purchased and placed into service qualifying depreciable property in 20X4 at a total cost of $2,250,000. Dolly has elected to take the Section 179 deduction. What is Dollys Section 179...
-
Ruth Ames died on January 10, 2015. In filing the estate tax return, her executor, Melvin Sims, elects the primary valuation date and amount (fair market value on the date of death). On March 12,...
-
On the night of October 14, 20X14, a hurricane caused serious damage to Paiges personal vehicle and to the roof of her personal residence, a townhome. Just prior to the hurricane, Paige had a...
-
In January 2014, Iris Corporation purchased and placed in service a 1933 building that houses retail businesses. The cost was $300,000, of which $25,000 applied to the land. In modernizing the...
-
Merton Enterprises has bonds on the market making annual payments, with 12 years to maturity, and selling for $963. At this price, the bonds yield 7.5 percent. What must the coupon rate be on...
-
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?
-
Jamie Lee is attracted to the low monthly payment advertised for a vehicle lease. She may well be able to afford a more expensive car than she originally thought. Jamie Lee really needs to think this...
-
Explain virtual hosting and how to use either name-based or IP-based virtual hosting.?
-
Discuss the role of literary allusion in satire as a means of subverting conventions and critiquing societal norms.
Study smarter with the SolutionInn App