Click here to Skip to main content
15,920,633 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Write a Program to design a class having static member function named show count () which has the property of displaying the number of objects created of the class

What I have tried:

Write a Program to design a class having static member function named show count () which has the property of displaying the number of objects created of the class
Posted
Updated 17-Feb-18 9:18am

 
Share this answer
 
Just a tip: you can override the default constructor of the class so that you can increment the static member variable, achieving the requested functionality.

Example of a class with default constructor defined, as well as a static member variable:
C++
/* Here is the class definition */
class MyClass
{

public:

   /* Here is a parameterless constructor */
   MyClass() {
      /* Code of the constructor goes here */
   }

private:

   /* Here is a static member variable definition */
   static int count;

};


Apart from that, your assignment is pretty straightforward; if you do not understand some of technical terms, you should ask to your teacher. For example, for the most of us a static member variable is pretty self explanatory, but if you do not understand it you should get back to the basis and learn all those technical terms.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900