Why do these errors come out?

0

Class code "linkedStackType"

#define LINKEDSTACKTYPE_H
#ifndef LINKEDSTACKTYPE_H
#endif
#include "NodoStack.h"
#include <cassert>

template < class TYPE > class linkedStackType {
public:
    bool isEmptyStack() const;
    bool isFullStack() const;
    void initializeStack();
    void push(const TYPE &newItem);

    TYPE top() const;
    void pop();
    linkedStackType();
    ~linkedStackType();

private:
    NodoStack< TYPE > *stackTop;

};

template < class TYPE> linkedStackType < TYPE > ::linkedStackType() {
    stackTop = NULL;
}

Main class code:

#include <iostream>
#include <stack>
#include "linkedStackType.h"
#include <string>
#include <cmath>
#include <cstdlib>
using namespace std;

void evaluarExpresionPostfija(string, linkedStackType < int >&, int &);
string conv_postfija(string &, string &);

int prioridad(char);
bool operador(char operador);
bool operando(char);

int main()
{  
    string exp_infija, exp_postfija = "";
    cout << "INGRESE EXPRESION INFIJA: ";
    getline(cin, exp_infija);

    conv_postfija(exp_infija, exp_postfija);
    cout << "EXPRESION POSTFIJA" << exp_postfija << endl;

    int resultado;
    linkedStackType <int> enteros;
    evaluarExpresionPostfija(exp_postfija, enteros, resultado);
    cout << "EL RESULTADO ES :  " << resultado << endl;

    return 0;
}

void evaluarExpresionPostfija(string expostfija, linkedStackType <int>& stack, int&valor) {
    int numero;
    stack.initializeStack();

    if (!expostfija.empty()) {
        while (!expostfija.empty()) {
            char indice = expostfija.at(0);
            expostfija = expostfija.substr(1, expostfija.length());
            string caracter = "";
            caracter += indice;

            if (operando(indice)) {
                numero = atoi(caracter.c_str());
                stack.push(numero);
            }
            if (operador(indice)) {
                int op2 = stack.top();
                stack.pop();

                if (stack.isEmptyStack()) {
                    cout << "EXPRESION INCORRECTA" << endl;
                    exit(1);
                }
                int op1 = stack.top();
                stack.pop();

                switch (indice) {
                   case '+': stack.push(op1 + op2);
                    break;
                   case '-': stack.push(op1 - op2);
                    break;
                   case '*': stack.push(op1*op2);
                       break;
                   case '/':
                       if (op2 != 0)
                           stack.push(op1 / op2);
                       else {
                           cout << "No se puede dividir entre cero" << endl;
                           exit(1);
                       }
                       break;
                   case '^': stack.push(int(pow(op1, double(op2))));
                       break;


                }
            }
        }//end while(expostfija.empty())
        valor = stack.top();
        stack.pop();
    }//endif


}
//-----------------------------
string conv_postfija(string&E_inf, string &E_post) {
    linkedStackType <char> postfija;
    char caracter;
    postfija.push('(');
    E_inf += ')';

    while (!postfija.isEmptyStack()) {
        caracter = E_inf.at(0);
        E_inf = E_inf.substr(1, E_inf.length());

        if (operando(caracter))
            E_post += caracter;
        if (caracter=='(')
            postfija.push(caracter);

        if (operador(caracter)) {
           if(operador(postfija.top()))
               while (prioridad(caracter) <= prioridad(postfija.top())) {
                   char arg = postfija.top();
                   E_post += arg;
                   postfija.pop();
                   if (!operador(postfija.top()))
                       break;
               }
           postfija.push(caracter);
        }
        if (caracter == ')') {
            while (postfija.top() != '(') {
                E_post += postfija.top();
                postfija.pop();
            }//endwhile
            return E_post;
        }

    }


}//endstring
//---------------------------------------------
int prioridad(char oper) {
    int prioridad = 0;
    if (operador(oper)) {
        switch (oper) {
        case '^': prioridad = 3;
            break;
        case '/': prioridad = 2;
            break;
        case '*': prioridad = 2;
            break;
        case '+': prioridad = 1;
            break;
        case '-': prioridad = 1;
            break;
        }

    }

}

Where I get these errors when compiling:

  

Severity Code Description Project File Line Deletion status   Error C2143 syntax error: missing ';' in front of '< Final c: \ users \ admin \ documents \ visual studio 2015 \ projects \ final \ final \ linkedstacktype.h 20

     

Severity Code Description Project File Line Deletion status   Error C4430 missing the type specifier; it is presupposed int. Note: C ++ does not support default-int Final c: \ users \ admin \ documents \ visual studio 2015 \ projects \ final \ final \ linkedstacktype.h 20

     

Severity Code Description Project File Line Deletion status   Error C2238 unexpected token (s) before ';' Final c: \ users \ admin \ documents \ visual studio 2015 \ projects \ final \ final \ linkedstacktype.h 20

I based myself on a tutorial of YT and I copied the code as shown there, step by step, that is why I do not understand those errors when they put on the "NodeStack" the error in the syntax, the tutorial came as are looking in the code and compiled. So I do not know what could be the error or if someone could guide me.

    
asked by D.Hazard 21.08.2017 в 21:12
source

1 answer

0
#define LINKEDSTACKTYPE_H
#ifndef LINKEDSTACKTYPE_H
#endif
#include "NodoStack.h"
#include <cassert>

The first three lines of the code above are called saves and serve to prevent a header from being imported several times (which causes problems because the symbols will appear defined before the compiler and may even implemented several times.

The problem here is that you are using the guard incorrectly. The saves should encapsulate all the header, while your saves is not encapsulating anything at all. It should look like this:

// Si no esta definido el simbolo...
#ifndef LINKEDSTACKTYPE_H 

// lo definimos
#define LINKEDSTACKTYPE_H

// Ahora incluimos todo el codigo del archivo
#include "NodoStack.h"
#include <cassert>

template < class TYPE > class linkedStackType {
// ...

// Y al final de la cabecera cerramos la guarda
// El comentario facilita la lectura del código cuando hay varias
// directivas del precompilador en el fichero
#endif // LINKEDSTACKTYPE_H 

To document the rest of the problems it would be necessary that you show the declaration of the class NodoStack

    
answered by 22.08.2017 в 08:21