All submissions
#include <iostream>
using namespace std;

class Device {
private:
   int id;
   static int count;
public:
   Device(int id_) : id(id_) {
       ++count;
   }
   static int getCount() {
       return Device::count;
   }
};

// static member is also required to declare out of class 
int Device::count = 0;

int main() {
   Device d1(1);
   Device d2(2);
   Device d3(3);
   cout << "Total devices created: " << Device::getCount();
   return 0;
}
Loading...

Input

Expected Output

Total devices created: 3