0

I find the error that is in the title, this in my program that is a static queue with all its methods or functions, this error is in the following function.

void Cola::queve(TIPO_DATO datos){
if(cola1.vacia()){
    final = (final+1)%TAM;
    datos[final] = datos;
}else{
    cout<<"No hay espacios en la cola"<<endl;
}
}

Anyway I leave the rest of the code in case something, I hope your answers thanks.

#include <iostream>
#include <stdlib.h>

using namespace std;

#define TAM 10
#define TIPO_DATO int

void menu();

class Cola{
private:
    TIPO_DATO  datos[TAM];
    int frente;
    int final;
public:
    void inicializa();
    bool vacia();
    bool llena();
    TIPO_DATO front();
    void queve(TIPO_DATO datos);
    void deque();
    void imprimir();
    void anular();
 };

 int main(){

 menu();
 return 0;
 }

 Cola cola1;

 void menu(){
 int opc;
 int a;

 cola1.inicializa();
 cout<<"\t \t ***** MENU PRINCIPAL *****"<<endl;
 cout<<"Selecciona la opcion deseeada"<<endl;
 cout<<"1. Vacia"<<endl;
 cout<<"2. Llena"<<endl;
 cout<<"3. Front"<<endl;
 cout<<"4. Encolar"<<endl;
 cout<<"5. Deseencolar"<<endl;
 cout<<"6. Imprimir"<<endl;
 cout<<"7. Anular"<<endl;
 cout<<"8. Salir"<<endl;
 cin>>opc;
 cout<<endl;
 switch(opc){
    case 1: cola1.vacia();
    break;
    case 2:
    break;
    case 3: cout<<"cola1.front()"<<endl;
    break;
    case 4:
    break;
    case 5:
    break;
    case 6:
    break;
    case 7: cola1.anular();
    break;
    case 8:
    break;  
  }

}

//Prototipos de la cola

void Cola::inicializa(){
frente = 0;
final = TAM-1;
}

bool Cola::vacia(){
if(frente == 0 && final == TAM-1){
    return true;
    cout<<endl;
    cout<<"La cola se encuentra vacia"<<endl;
}else{
    return false;
    cout<<endl;
    cout<<"La cola no esta vacia"<<endl;
}
system("PAUSE");
menu();
}

bool Cola::llena(){

}

void Cola::queve(TIPO_DATO datos){
if(cola1.vacia()){
    final = (final+1)%TAM;
    datos[final] = datos;
}else{
    cout<<"No hay espacios en la cola"<<endl;
}
}

void Cola::deque(){

}

TIPO_DATO Cola::front(){
if(cola1.vacia()){
    return datos[frente];
}
else{
    cout<<"Error"<<endl;
}
}

void Cola::imprimir(){

}

void Cola::anular(){
frente = 0;
final = TAM-1;

}
3
  • 1
    Don't use the same name for an argument as for a member variable. You're just lucky that it's a compilation error in this case. Commented Sep 29, 2022 at 12:54
  • It's also a bad idea to use plural names for singular things ("dato"/"datos"); nothing after a return ever gets executed (see vacia); the queue should not be concerned with pausing or the menu (also vacia); and a function that is supposed to return a value should always return a value (see front and llena). Commented Sep 29, 2022 at 13:10
  • Enable your compiler warnings. Fix the warnings. Your compiler could have told you that you made this mistake. Commented Sep 29, 2022 at 13:45

1 Answer 1

2

The function parameter datos hides the members variable of the same name, either

  • use different name:

    void Cola::queve(int new_datos){
        if(cola1.vacia()){
            final = (final+1)%TAM;
            datos[final] = new_datos;
        }else{
            cout<<"No hay espacios en la cola"<<endl;
        }
    }
    
  • or use this-> for the hidden member variable:

    void Cola::queve(int datos){
        if(cola1.vacia()){
            final = (final+1)%TAM;
            this->datos[final] = datos;
        }else{
            cout<<"No hay espacios en la cola"<<endl;
        }
    }
    
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.