Skip to content

Instantly share code, notes, and snippets.

@webber2408
Created April 11, 2020 16:43
Show Gist options
  • Save webber2408/1265b37bb8c223e31c84abbac70ea5e1 to your computer and use it in GitHub Desktop.
Save webber2408/1265b37bb8c223e31c84abbac70ea5e1 to your computer and use it in GitHub Desktop.
#include<iostream>
using namespace std;
class Country{
public:
string name;
int populationCount;
static int countryCount;
void setCountryDetails(string s, int n){
this->name = s; // or name = s
this->populationCount = n;
countryCount++;
}
static int getTotalCountryCount(){
return countryCount;
}
};
int Country::countryCount = 0;
int main(){
Country c1;
c1.setCountryDetails("India", 1300000000);
Country c2;
c2.setCountryDetails("USA", 328200000);
cout<<"Total Countries: "<<Country::getTotalCountryCount()<<endl;
}
/*
Output:
Total Countries: 2
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment