-1
I’m having trouble storing information inside a vector. I need to store information like a user’s name, password and account number, so I’m using a struct
typedef struct {
int conta;
string nome;
double saldo;
int senha;
} Cliente ;
And a vector of the struct type
vector <Cliente> clientes_;
And the role in which saving a customer’s information is this:
char opcaoMenu(char opc){
Cliente cliente;
do{
cin >> opc;
if (opc == '1'){
acessarConta();
}
else if (opc =='2'){
clientes_.push_back(cadastrarConta());
acessarConta();
}
else{
cout << "Opção inválida! Divite novamente!" << endl<< "Escolha uma opção >>> ";
}
}while (opc > '2');
return opc;
}
The push_back registration function is this
Cliente cadastrarConta() {
Cliente cliente;
cin.ignore();
cout << "Digite seu nome: ";
getline(cin, cliente.nome);
cout << "Digite uma senha nuḿerica: ";
cin >> cliente.senha;
cliente.conta = (cliente.senha + rand() % 8000 + 1000);
cout << "Sua conta é: " << cliente.conta;
return cliente;
}
When I give the make, I get this output in the terminal:
g++ functions.cpp main.cpp -the test. o /tmp/ccwJox4M:(.bss+0x0): multiple definitions of "clientes_" /tmp/ccyG79Ya.o:(.bss+0x0): first defined here collect2: error: Ld returned 1 Exit status make: *** [Makefile:3: all] Error 1
I just need to know where I’m going wrong. Anything the project repository is this: https://gitlab.com/peidrao/caixa-eletronico
Take care with using namespace, mainly in headers.
– Arthur Passos