Need a project done?

C++ Programming Developer

Search This Blog

Use of Static in Classes C++

Use of static in Classes in C++ can bee seen through following program.

#include <iostream>
using std::cout;
using std::endl;
using std::cin;
class UniquelyIdentified{
const int getUniqueID() const;
static int ID;
int UniquelyIdentified::ID = 0;
int main(){
cout << "Press 'c' to create new Object, -1 to exit" << endl;
char opt;
while ((cin>>opt) && (opt=='c')){
UniquelyIdentified obj;
cout << "Get ID? (y/n) ";
char o;
if ((cin >> o) && (o=='y')){
cout << "ID of current Object: " << obj.getUniqueID() << endl;
return 0;
const int UniquelyIdentified::getUniqueID() const{
return ID;
"Don't let anyone ever make you feel like you don't deserve what you want."