#include <iostream>
using namespace std;
class Stos {
public:
int* element;
int wierzcholek;
int rozmiar;
Stos(const Stos& s)
{
rozmiar = s.rozmiar;
wierzcholek = s.wierzcholek;
element = new int[s.rozmiar];
*element = *s.element;
cout << "Wywolanie Konstruktora Kopiującego:" << this << endl;
}
Stos()
{
element = new int[10];
rozmiar = 10;
wierzcholek = -1;
cout << endl
<< "wywoluje konstruktor domyslny i pisze adres:" << this << endl;
}
Stos(int x)
{
element = new int[x];
rozmiar = x;
wierzcholek = -1;
cout << endl
<< "wywoluje konstruktor z rozmiaremi pisze adres:" << this << endl;
}
~Stos()
{
delete[] element;
cout << endl
<< "wywoluje destruktor i pisze adres:" << this << endl;
}
void push(int liczba)
{
if (wierzcholek != rozmiar) {
wierzcholek++; // cout<<"wypisz wierzcholek:"<<wierzcholek<<endl;
element[wierzcholek] = liczba;
}
else {
cout << "nie mozna dodac,stos pelny" << endl;
}
}
int top()
{
return element[wierzcholek];
}
void pop()
{
element[wierzcholek] = NULL;
wierzcholek--;
}
int empty()
{
if (wierzcholek == -1)
return 1;
else
return 0;
}
};
void dodaj(Stos s, int a)
{
s.push(a);
}
int main()
{
Stos s;
s.push(0);
//s.push(1);
//s.push(2);
dodaj(s, 1); // wywolanie konstruktora kopiującego
dodaj(s, 2); // wywolanie konstruktora kopiującego
while (!s.empty()) {
cout << s.top();
s.pop();
}
return 0;
}
Mam ogromny problem z napisaniem konstruktora. Nie mogę zmieniać nic w mainie anie w funkcji dodaj.