Please, could you help me!?
Errors are for all headers in the stack.cpp file that references stack.h. It involves use of Templates.
Battery code.h:
#ifndef PILHA_H
#define PILHA_H
#include <iostream>
//#include <cstdlib>
template <typename T>
class Pilha{
T * vetor;
int tam;
int topo;
public:
Pilha(int size);
~Pilha();
void Print();
void Push(T vetor);
T Pop();
T Topo();
void Limpar();
bool Vazio();
bool Cheio();
};
#include "pilha.cpp"
#endif
Battery code.cpp:
#include<iostream>
#include "pilha.h"
//Construtor
template <typename T>
Pilha<T>::Pilha(int size){
vetor = new T[size];
this->tam = size;
topo = -1;
}
//Destrutor: remove o vetor completamente
template <typename T>
Pilha<T>:: ~Pilha(){
delete [] vetor;
topo = -1;
}
//Inserindo conteúdo:
template <typename T>
void Pilha<T>::Push(T n){
if(Cheio())
std:: cout << "Erro: Pilha cheia" << std::endl;
else
this->vetor[++topo] = n;
//topo++;
}
//Removendo conteúdo;
template <typename T>
T Pilha<T>::Pop(){
T aux = Topo();
topo--;
return aux;
}
//Topo da pilha:
template <typename T>
T Pilha<T>::Topo(){
if(Vazio())
std::cout << "Erro: Pilha cheia" << std::endl;
else
return vetor[topo];
}
//Limpando a pilha:
template <typename T>
void Pilha<T>::Limpar(){
delete [] vetor;
topo = -1;
}
//Pilha vazia:
template <typename T>
bool Pilha<T>::Vazio(){
if(topo == -1){
std::cout << "Pilha vazia" << std::endl;
return true;
}
else
return false;
}
//Pilha cheia:
template <typename T>
bool Pilha<T>::Cheio(){
if(topo == tam - 1){
std::cout << "Pilha Cheia" << std::endl;
return true;
}
else
return false;
}
//Exibindo os elementos da pilha:
template <typename T>
void Pilha<T>::Print(){
for(int i = topo; i > -1; i--){
std::cout << vetor[i] << " ";
}
}
Build Screen: