// statfunc.cpp // Статические функции и ID объектов #include using namespace std; /////////////////////////////////////////////////////////// class gamma { private: static int total; //всего объектов класса //(только объявление) int id; //ID текущего объекта public: gamma() //конструктор без аргументов { total++; //добавить объект id = total; //id равен текущему значению total } ~gamma() //деструктор { total--; cout << "Удаление ID " << id << endl; } static void showtotal() // статическая функция { cout << "Всего: " << total << endl; } void showid() // Нестатическая функция { cout << "ID: " << id << endl; } }; //--------------------------------------------------------- int gamma::total = 0; // определение total /////////////////////////////////////////////////////////// int main() { gamma g1; gamma::showtotal(); gamma g2, g3; gamma::showtotal(); g1.showid(); g2.showid(); g3.showid(); cout << "----------конец программы----------\n"; return 0; }