answersLogoWhite

0


Best Answer
  • Create a static member variable to contain the count. This variable is common to all instances of the class.
  • Initialize that variable to zero at the beginning of the program.
  • In the class constructor, increment the variable.
  • In the class destructor, decrement the variable.
User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: A class in a program whose objects are created and destroyed throughout the program It is desired that the total number of live objects in the program be known how you do this in C plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

When you charge objects by any method no charges are?

created or destroyed


What objects can't be destroyed?

Matter can neither be created or destroyed, the same goes for energy


Can we create an array of objects for a class having default constructor Justify your answer?

See example code below. #include <iostream> class x { private: // Members. static int counter; int data; public: // Default constructor and destructor. x():data(++counter){printf("Object %d created!\n",data);} ~x(){printf("Object %d destroyed!\n",data);} // other members omitted for brevity... }; // Initialise static counter. int x::counter=0; int main() { // Instantiate an array of 10 objects. x arr[10]; // .. do some work with the array .. return( 0 ); // The array falls from scope, destroying the objects. } Example output: Object 1 created! Object 2 created! Object 3 created! Object 4 created! Object 5 created! Object 6 created! Object 7 created! Object 8 created! Object 9 created! Object 10 created! Object 10 destroyed! Object 9 destroyed! Object 8 destroyed! Object 7 destroyed! Object 6 destroyed! Object 5 destroyed! Object 4 destroyed! Object 3 destroyed! Object 2 destroyed! Object 1 destroyed!


How would you define energy?

energy is a property of objects, transferable among them via fundamental interactions, which can be converted into different forms but not created or destroyed.


Explain How electrically neutral objects can become electrically charge even though charge Cannot be created or destroyed.?

They acquire a charge from somewhere else.


What cannot be destroyed by volcanoes?

concrete houses flying objects


When was Vision Objects created?

Vision Objects was created in 1998.


When was Objects of Desire created?

Objects of Desire was created in 1982.


When was Strange Objects created?

Strange Objects was created in 1990.


When was Business Objects created?

Business Objects was created in 1990.


What is the big idea of energy transfer in elementary science?

Energy can be transferred between objects, and can change its form.However, energy is neither created nor destroyed.(Law of Conservation of Energy)


When was Intelligent Medical Objects created?

Intelligent Medical Objects was created in 1994.