// #include <iostream>
// using namespace std;
// class Device {
// private:
// int id;
// static int count;
// public:
// Device(int id_) : id(id_) {
// count++;
// }
// static int getCount() {
// return 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;
// }
#include<iostream>
using namespace std;
class Device{
private:
//int id;
static int count;
public:
Device(int id_) : id(id_){
count++;
}
static int getCount(){
return count;
}
};
int Device:: count =0;
int main(){
Device d1;
Device d2;
Device d3;
cout<<"Total devices created: "<< Device::getCount();
}
// class Device {
// private:
// static int count;
// public:
// Device(){
// count++;
// }
// static int getCount(){
// return count;
// }
// };
Input
Expected Output
Total devices created: 3