Thursday, February 4, 2021

Program to Count the number of objects using the Static member function in c++

Design a class having static member function name show count() which has the property of displaying the number of objects creator of the class.

class test 
  int code;
  static int count;
  void set code(void)
  void showcode(void)
    count<<"object number:"<<code<<"\n";
  static void show count(void)
int test ::count;
void main()
   test t1,t2;
   test t3;

Output :

count = 3;
object1 = 1;
object2 = 2;
object3 = 3;

No comments:

Post a Comment