User forums > Help

Program erro, please help std::bad_alloc

(1/1)

davidppr:
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
--- End code ---

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);
            }
    }
   
   
   
     }
--- End code ---

oBFusCATed:
Wrong forum...Read the rules and find something which deals with programming questions.

Navigation

[0] Message Index

Go to full version