Implementation of Stack using Linked List
You leak every single node you pop. You need to delete the node.

You should add move and emplace push overloads. So that non-copyable T can be stored.

you check against "overflow" by testing top is less than -1. However signed overflow is undefined behavior and if you ever had more than 2 billion items in your stack you probably ran out of ram earlier. You can check if the stack is empty by testing if head is nullptr. So top isn't really necessary.

For every operation you seek the end of the stack, that is not necessary at all.

template&lt;class T&gt;
void Stack&lt;T&gt;::push(T val){
    top++;
    Node *node=new Node(val);
    node-&gt;next = head;
    head=node;
}

template&lt;class T&gt;
T Stack&lt;T&gt;::pop(){
  if(stack_empty()==true)
    std::cout&lt;&lt;"Underflow"&lt;&lt;std::endl;
  else{
    top--;
    Node *node=head;
    head = node-&gt;next;
    T tmp = std::move(node-&gt;data);
    delete node;
    return tmp;
  }
}