Author Topic: Program erro, please help std::bad_alloc  (Read 2690 times)

davidppr

  • Guest
Program erro, please help std::bad_alloc
« on: May 05, 2020, 03:17:12 am »
hello, I'm brazillian, so sorry for the write.

I have a problem, I created a function telaInicio(), in her I need create several perfils of class Perfil.
Then I have this message, when I create the second Perfil. What can I do?

Code
      terminate called after throwing an instance of 'std::bad_alloc'
          what():  std::bad_alloc

Here the function:

   
Code
void telaInicio(RedeSocial* r1){
      int opcaoinicio=0;
   
   
   
      cout << r1->quantidadeDePerfis;
      cout << endl << "Escolha uma opcao: ";
      cout << endl << "1) Cadastar Perfil ";
      cout << endl << "2) Cadastrar Disciplina";
      cout << endl << "3) Logar";
      cout << endl << "0) Terminar " << endl;
      cin >> opcaoinicio;
   
   
       if (opcaoinicio==1){
            int numerouspper=0;
   
            string nomeper="";
            string emailper="";
            string respprofessor="";
   
            cout << endl << "Informe os dados do perfil " << endl;
            cout << "Numero USP: ";
            cin >> numerouspper;
            cout << "Nome: ";
            cin >> nomeper;
            cout << "Email: ";
            cin >> emailper;
            cout << "Professor (s/n): ";
            cin >> respprofessor;
            if (respprofessor=="n"){
   
                Perfil* p1= new Perfil(numerouspper,nomeper,emailper);
   
                r1->adicionar(p1);
   
                r1->imprimir();
                telaInicio(r1);
   
   
            }else{
                cout << "Departamento: ";
                cin >> respprofessor;
   
                r1->imprimir();
   
                telaInicio(r1);
            }
    }
   
   
   
     }

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Program erro, please help std::bad_alloc
« Reply #1 on: May 05, 2020, 07:27:54 pm »
Wrong forum...Read the rules and find something which deals with programming questions.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]