Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //objects.h
- #ifndef OBJECTS_H
- #define OBJECTS_H
- class objects {
- private:
- double data; // сами данные
- static objects* array[255];
- static int count;
- public:
- objects(int data);
- ~objects();
- static int get_quantity();
- static objects* get_link(int i);
- };
- #endif // OBJECTS_H
- //objects.cpp
- #include "objects.h"
- #include <iostream>
- int objects::count = 0;
- objects* objects::array[255];
- objects::objects(int data) {
- array[count] = this;
- count++;
- this->data = data;
- std::cout << "Added new element with data = " << this->data << std::endl;
- }
- objects::~objects() {
- count--;
- std::cout << "Element has been deleted.\n";
- }
- int objects::get_quantity() {
- return count;
- }
- objects* objects::get_link(int i) {
- return array[i];
- }
- //main.cpp
- #include <iostream>
- #include <objects.h>
- int main() {
- for(int i = 0; i < 8; i++)
- objects *temp = new objects(i*i);
- std::cout << "\nNumber of elements: " << objects::get_quantity()
- << "\nList of links to the registered objects:\n[ ";
- for(int i = 0; i < objects::get_quantity(); i++)
- std::cout << objects::get_link(i) << " ";
- std::cout << "]\n\n";
- for(int i = 0; i < 8; i++)
- delete objects::get_link(i);
- std::cout << "\nNumber of elements: " << objects::get_quantity() << ".\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment