CS 12 - Static Keyword


CS 12 Homepage

A Lot of Static

Note: We will be having a practical examination in lab today. Download the following code and modify it to read in numbers from the user until the user hits Control D. There is no limit of the amount of numbers that the user can enter, so arrays are not advised. The code for this assignment can be found here.

Static

The static keyword in C++ has many features, which are useful in differing circumstances. Generally you can think of static as meaning "Only one copy," although there are some uses that don't quite fit this description. Lets look at some of the uses for the "static" modifier.

The Assignment

7 pointsWrite a class that counts how many instances of that class are currently allocated. Give that class two constructors, each of which has a static variable that counts how many times that constructor has been called. Check that the sum of those two values is equal to the counter. (Thus we have 2 function-level static variables and 1 class-level static variable.)

Assorted Questions

Answer these questions in "questions.txt" unless told otherwise

© 2003 UC Riverside Department of Computer Science & Engineering. All rights reserved.