error: no match for 'operator' (operand types are 'std :: ostream {aka std :: basic_ostreamchar}' and 'const std :: runtime_error')

0

Program code

main

#include <iostream>
#include "CntrIU.h"
#include "CntrNeg.h"
#include "interfaces.h"
#include "stubs.h"
#include <cstdlib>

using namespace std;

int main()
{
    IUAutenticacao *CntrAut = new CntrIUAut();
    ILNAutenticacao *CntrLNA = new CntrLNAutenticar();
    ResultAut resulted;

    CntrAut->setCntrLNAutenticacao(CntrLNA);
    try{
        resulted = CntrAut->autenticar();
    }catch(const runtime_error &e){
        cout << "Erro falha no sistema" << endl;
    }

    if(resulted.getValor()==ResultAut::sucesso){
        cout << "Autenticacao feita com sucesso" << endl;
    }

    return 0;
}

Stubs.h

#ifndef STUBS_H
#define STUBS_H
#include "Entidades.h"
#include "Dominios.h"
#include "Interfaces.h"
#include "Comandos.h"
#include <stdexcept>
#include <iostream>
#include <windows.h>
#include <typeinfo>
class StubIPersistencia:public IPersistencia
{
    private:
        TRIGGERS t;
    public:
        void executar(CmdBD*)throw(runtime_error);
};
#endif // STUBS_H

Stubs.cpp

void StubIPersistencia::executar(CmdBD*cmd)throw(runtime_error)
{
    try{
        if(typeid(*cmd) == typeid(CmdRecuperarSenha)){
            cmd->executar();
        }
        if(typeid(*cmd) == typeid(CmdIncluirGerProj)){
            cmd->executar();
        }
        if(typeid(*cmd) == typeid(CmdEditarGerProj)){
            cmd->executar();
        }
        if(typeid(*cmd) == typeid(CmdRecuperarGerProj)){
            cmd->executar();
        }
        if(typeid(*cmd) == typeid(CmdRemoverGerProj)){
            cmd->executar();
        }
        if(typeid(*cmd) == typeid(CmdIncluirDesenv)){
            cmd->executar();
        }
        if(typeid(*cmd) == typeid(CmdEditarDesenv)){
            cmd->executar();
        }
        if(typeid(*cmd) == typeid(CmdRecuperarDesenv)){
            cmd->executar();
        }
        if(typeid(*cmd) == typeid(CmdRemoverDesenv)){
            cmd->executar();
        }
        if(typeid(*cmd) == typeid(CmdIncluirProj)){
            cmd->executar();
        }
        if(typeid(*cmd) == typeid(CmdEditarProj)){
            cmd->executar();
        }
        if(typeid(*cmd) == typeid(CmdRecuperarProj)){
            cmd->executar();
        }
        if(typeid(*cmd) == typeid(CmdRemoverProj)){
            cmd->executar();
        }
    }catch(const runtime_error&e){
        throw runtime_error(e);
    }
}

Commands.h

#ifndef COMANDOS_H
#define COMANDOS_H
#include "Entidades.h"

class CmdBD
{
    public:
        virtual void executar()throw(runtime_error) = 0;
        virtual ~CmdBD(){};
};

class CmdRecuperarSenha:public CmdBD
{
    private:
        matricula m;
    public:
        void executar()throw(runtime_error);
        CmdRecuperarSenha(matricula x);
};
#endif // COMANDOS_H

Commands.cpp

CmdRecuperarSenha::CmdRecuperarSenha(matricula x)
{
    this->m = x;
}

void CmdRecuperarSenha::executar()throw(runtime_error)
{
    if(m.get()==TRIGGERSP::TRIGGERSUCESSOMAT){
        return;
    }else if(m.get()==TRIGGERSP::TRIGGERFALHAMAT){
        throw runtime_error("Erro no Banco de Dados Ao Recuperar Senha");
    }
}

Interfaces.h

#ifndef INTERFACES_H
#define INTERFACES_H

#include "dominios.h"
#include "entidades.h"
#include "Comandos.h"
#include <stdexcept>

using namespace std;


class IUAutenticacao{
    public:
        virtual ResultAut autenticar() throw(runtime_error) = 0;
        virtual void setCntrLNAutenticacao(ILNAutenticacao *) = 0;
};
class ILNAutenticacao{
    public:
        virtual ResultAut autenticar(const matricula&,const senha&) throw(runtime_error) = 0;
};
class IPersistencia{
    public:
        virtual void executar(CmdBD*)throw(runtime_error) = 0;
};
#endif // INTERFACES_H

CntrIU.h

#ifndef CNTRIU_H
#define CNTRIU_H

#include "interfaces.h"
#include "stubs.h"
#include "Comandos.h"
#include <stdexcept>
#include <cstdlib>
#include <iostream>
#include <cstdio>

using namespace std;

class CntrIUAut:public IUAutenticacao
{
    private:
        ILNAutenticacao *cntrLNAutenticacao;
    public:
        ResultAut autenticar() throw(runtime_error);
        void setCntrLNAutenticacao(ILNAutenticacao *cntrLNAutenticacao);
};

CntrIU.cpp

#include "CntrIU.h" 
ResultAut CntrIUAut::autenticar() throw(runtime_error)
    {
        ResultAut result;
        matricula m;
        senha s;
        string n;
        bool t = true;

        while(t == true){
            system("cls");
            cout << "Autenticacao Usuario" << endl;
            try{
                cout << "Digite sua Matricula: "<< endl;
                cin >> n;
                m.Set(n);
                cout << "Digite sua Senha: "<< endl;
                cin >> n;
                s.Set(n);
                t = false;
            }catch(const invalid_argument &e){
                system("cls");
                cout << "Dados Inseridos INVALIDOS" << endl;
                getchar();
            }
        }

        result = cntrLNAutenticacao->autenticar(m,s);

        if(result.getValor() == ResultAut::falha){
            cout << "Falha na autenticacao" << endl;
        }

        return result;
    }


    void CntrIUAut::setCntrLNAutenticacao(ILNAutenticacao *cntrLNAutenticacao)
    {
        this->cntrLNAutenticacao = cntrLNAutenticacao;
    }

CntrNeg.h

#ifndef CNTRNEG_H
#define CNTRNEG_H
#include "Interfaces.h"
#include "stubs.h"
#include "Comandos.h"
#include <iostream>
#include <stdexcept>
#include <windows.h>

using namespace std;


class CntrLNAutenticar:public ILNAutenticacao {
    private:
        IPersistencia * CntrPersistencia;
    public:
        void setCntrPersistencia(IPersistencia * CntrPersistencia);
        ResultAut autenticar(const matricula&,const senha&)throw(runtime_error); };
#endif // CNTRNEG_H

CntrNeg.cpp

ResultAut CntrLNAutenticar::autenticar(const matricula&m,const senha&s)throw(runtime_error)
{
    ResultAut result;
    CntrPersistencia = new StubIPersistencia();
    CmdBD *cmd = new CmdRecuperarSenha(m);

    cout << "Autenticando..." << endl;
    cout << "matricula:" << m.get() << endl;
    cout << "senha:" << s.get() << endl;

    Sleep(1000);

    try{
        CntrPersistencia->executar(cmd);
        result.setValor(ResultAut::sucesso);
    }catch(const runtime_error &e){
        cout << e << endl;
        result.setValor(ResultAut::falha);
    }

    return result;
}

Well I'm having this problem, more precisely in this part of my code

try{ CntrPersistencia->executar(cmd); result.setValor(ResultAut::sucesso); }catch(const runtime_error &e){ cout << e << endl; result.setValor(ResultAut::falha); }

I'm not going to post all the code, because it's a giant code, the problem is print that I try to give in the error and the constant that I stated in catch

  

error: no match for 'operator

asked by anonymous 30.11.2016 / 16:45

0 answers