Call a function based on struct passed in reference?

0

How do I call the menu function by passing more than one struct per reference according to validation in the validation function?

I'm sorry I'm starting now and I decided to do this little exercise to practice functions, classes, and structs and I came across this problem that I can not solve. Can someone please help me?

class Conta {

 private:


struct cliente_1 {
    string nome = "Odair";
    int conta = 739146;
    double senha = 759247;
    float saldo = 00.00;
    double cpf = 48730701875;
};

struct cliente_2 {
    string nome = "Leo";
    int conta = 135478;
    double senha = 789878;
    float saldo = 00.00;
    double cpf = 48730701875;
};


struct cliente_3 {
    string nome = "Caio";
    int conta = 789757;
    double senha = 24860165;
    float saldo = 00.00;
    double cpf = 48730701875;
};

struct clientes {

    cliente_1 c1;
    cliente_2 c2;
    cliente_3 c3;

};
 public:

void menu( cliente_1 cont) {


    cout << cont.nome << endl;
    system("pause");




}
void validacao(int x, double  y) {

    cliente_1 c1;
    cliente_1 c2;
    cliente_1 c3;


    if (x == 739396 || y == 759247) {

        menu(c1);
    }
    else if (x == 135478 || y == 789878) {

        menu(c2);
    }
    else if (x == 789757 || y == 24860165) {

        menu(c3);
    }



}
    
asked by anonymous 10.01.2018 / 14:04

1 answer

0

Although your 3 struct has exactly the same format, they are declared to be different so you will not be able to pass them to your function, the compiler will accuse you as an error.

You can create a single Struct and then create 3 instances of it.

struct Cliente {
    string nome;
    int conta;
    double senha;
    float saldo;
    double cpf;
};

Cliente c1, c2, c3;

// adiciona os valores aos Structs antes de começar a modificalos
void IniciarClientes()
{
    c1.nome = "Odair";
    c1.conta = 739146;
    c1.senha = 759247;
    c1.saldo = 00.00;
    c1.cpf = 48730701875;

    c2.nome = "Leo";
    // e continua o restante
}

// passando como referencia como você pediu na pergunta
void menu(Cliente *cliente) 
{
    cout << cliente->nome << endl;
    system("pause");
}

void validacao(int x, double  y)
{
    if (x == 739396 || y == 759247) 
    {
        // passando como referencia
        menu(&c1);
    }
    else if (x == 135478 || y == 789878) 
    {
        menu(&c2);
    }
    else if (x == 789757 || y == 24860165)
    {
        menu(&c3);
    }
}
    
10.01.2018 / 14:34