Created
September 21, 2014 21:41
-
-
Save kolodziej/dcf52e1bcfa443d2bb32 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class kontener | |
{ | |
int *T, n; | |
public: | |
kontener(int n_) : T(new int[n_]), n(n_) | |
{ | |
std::cout << "tworzenie kontenera o poj. " << n << " pod adresem: " << reinterpret_cast<const void*>(this) << "\n";; | |
} | |
kontener(const kontener& zrodlo) : T(new int[zrodlo.pobierz_n()]), n(zrodlo.pobierz_n()) | |
{ | |
std::cout << "konstruktor kopiujący z " << reinterpret_cast<const void*>(&zrodlo) << " do " << reinterpret_cast<const void*>(this) << "\n"; | |
copy(zrodlo.pobierz_T(), zrodlo.pobierz_T()+n, T); | |
} | |
kontener(kontener &&zrodlo) : T(zrodlo.pobierz_T()), n(zrodlo.pobierz_n()) | |
{ | |
std::cout << "konstruktor przenoszacy z " << reinterpret_cast<const void*>(&zrodlo) << " do " << reinterpret_cast<const void*>(this) << "\n"; | |
zrodlo.reset_T(); | |
} | |
~kontener() | |
{ | |
std::cout << "usuwanie kontenera (adres: " << reinterpret_cast<const void*>(this) << ")\n"; | |
delete[] T; | |
} | |
kontener& ustaw(int index, int wartosc) | |
{ | |
T[index % n] = wartosc; | |
return *this; | |
} | |
void wyswietl() | |
{ | |
for (int i = 0; i < n; cout << T[i++] << " "); | |
cout << "\n"; | |
} | |
int pobierz_n() const | |
{ | |
return n; | |
} | |
int* pobierz_T() const | |
{ | |
return T; | |
} | |
int reset_T() | |
{ | |
T = nullptr; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment