Skip to content

Instantly share code, notes, and snippets.

@kolodziej
Created September 21, 2014 21:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kolodziej/dcf52e1bcfa443d2bb32 to your computer and use it in GitHub Desktop.
Save kolodziej/dcf52e1bcfa443d2bb32 to your computer and use it in GitHub Desktop.
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