#include <iostream>
using namespace std;
class Stack {
public:
int* arr;
int elements;
int sizestack = 1;
public: Stack()
{
arr = new int[sizestack];
elements = 0;
cout << "\nKONSTRUTOR DOMYSLNY: " << this << "\n";
}
public: Stack(int elem)
{
sizestack = elem;
cout << "\nKONSTRUTOR PARAMETR: " << this << "\n";
arr = new int[sizestack];
elements = 0;
}
public: void push(int data)
{
if (elements >= sizestack)
{
return;
}
arr[elements] = data;
elements++;
}
public: int top()
{
if (elements == 0)
{
return 0;
}
return arr[elements - 1];
}
public: void pop()
{
if (elements == 0)
{
return;
}
arr[elements] = NULL;
elements--;
}
bool full()
{
if (sizestack == elements)
{
return true;
}
return false;
}
bool empty()
{
if (elements == 0)
{
return true;
}
return false;
}
void destroy()
{
while (!empty())
{
pop();
}
}
void print()
{
for (int i = 0; i < elements; i++)
{
cout << arr[i] << ", ";
}
}
public: ~Stack()
{
cout << "\nDESTRUKTOR STOSU: " << this << "\n";
}
};
void f(Stack s, int a) {
s.push(a);
}
int main() {
Stack s(6);
s.push(0);
f(s, 1);
f(s, 4);
while (!s.empty()) {
cout << "TAKI TOP: " << s.top() << " ";
s.pop();
}
return 0;
}
I tried so hard and got so far, but in the end it doesn't even matter Why f(); function doesn't push element and it only prints the destructor message without the construcor one. How to fix this without changing main and f() function?