Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- template <typename T>
- class Znak {
- int rozmiar{};
- T** tab{ nullptr };
- public:
- Znak() = default;
- ~Znak();
- void operator+=(T* obiekt);
- T*& operator[](int index);
- const T*& operator[](int index) const;
- };
- template <typename T>
- Znak<T>::~Znak() {
- if (rozmiar > 0) {
- for (int i{}; i < rozmiar; ++i) {
- delete tab[i];
- }
- delete[] tab;
- }
- }
- template <typename T>
- void Znak<T>::operator+=(T* obiekt) {
- if (rozmiar == 0) {
- tab = new T * [1];
- }
- else {
- T** temp{ new T * [rozmiar + 1] };
- for (int i{}; i < rozmiar; ++i) {
- temp[i] = tab[i];
- }
- delete[] tab;
- tab = temp;
- }
- tab[rozmiar] = obiekt;
- ++rozmiar;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement