Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <memory>
- #include <string>
- using namespace std;
- template <typename T>
- ////////////////////////////////////////////////////////////////
- class MyPtr
- {
- T *ptr;
- public:
- static int n;
- MyPtr(T *p = nullptr): ptr(p)
- {
- n ++;
- cout << "*ptr = "<< *ptr << ", Создано указателей: " << n << endl;
- }
- ~MyPtr()
- {
- delete ptr;
- n --;
- cout << "Осталось указателей: " << n << endl;
- }
- T& operator*() { return *ptr; }
- };
- //int MyPtr<>::n = 0;
- template <typename T>
- int MyPtr<T>::n = 0;
- ////////////////////////////////////////////////////////////////////////
- int main() //
- {
- setlocale(LC_ALL, "rus");
- MyPtr<int> ptr_1(new int(42222));
- cout << "*ptr_1 = " << *ptr_1 << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment