I'm trying to implement a stack using linked list in cpp. I'm using class to make the linked list but I'm getting the following error and I dont understand why
#include <bits/stdc++.h>
using namespace std;
class Stack{
public:
int top;
Stack* next;
Stack(int data){ //constructor
top = data;
next = NULL;
}
void push(Stack* &head, int data);
int pop(Stack* &head);
bool empty(Stack* &head);
};
void Stack::push(Stack* &head, int data){
Stack* s = new Stack(data);
s->next = head;
head = s;
}
int pop(Stack* &head){
int x = head->top;
head = head->next;
return x;
}
bool empty(Stack* &head){
if(head == NULL)
return true;
return false;
}
int main() {
class Stack* s = new Stack(1);
s.push(2);
s.push(3);
cout << s.empty(s) << endl;
cout << s.pop(s) << endl;
cout << s.pop(s) << endl;
cout << s.pop(s) << endl;
cout << s.empty(s) << endl;
}
ERROR: request for member 'push' in 's', which is of pointer type 'Stack*' (maybe you meant to use '->' ?)
request for member 'empty' in 's', which is of pointer type 'Stack*' (maybe you meant to use '->' ?)
request for member 'pop' in 's', which is of pointer type 'Stack*' (maybe you meant to use '->' ?)
When I used -> instead of . it said undefined reference to Stack::empty(Stack*&) and undefined reference to Stack::pop(Stack*&)
EDIT: I used -> instead of . and added Stack:: to pop and empty function and it worked but the constructor isn't working