0
I’m having a problem with the pointer on customers. I call the function newCustomer(), that inserts nodes in the list hanging on customers. The problem is that every time the program leaves the function newCustomer(), customers comes true again nullptr.
Below is the function call, in the main():
case 1:
newCustomer(customers);
break;
The function newCustomer() is this:
void newCustomer(Cliente *customers){
int num;
string nome;
Cliente *qwe, *next;
cout << "Numero de clientes: ";
cin >> num;
qwe = customers;
if(customers == nullptr){
cout << "oi" << endl;
customers = new Cliente();
cout << "Nome do cliente: ";
setbuf(stdin, 0);
getline(cin, nome);
customers->setName(nome);
customers->setid(num);
qwe = customers;
num--;
}
while(qwe->getProx() != nullptr){
qwe = qwe->getProx();
}
while( num != 0){
next = new Cliente();
qwe->setProx(next);
qwe = qwe->getProx();
cout << "Nome do cliente: ";
setbuf(stdin, 0);
getline(cin, nome);
qwe->setName(nome);
qwe->setid(num);
num--;
}
}
I would also like to ask for some tips on how to improve my code. I’m starting at C++ now, I accept all criticism :)

I get it. Really, like you said, I learned to code in C and I can’t disguise kkkk. In C I always passed pointers by reference like that, I thought here would also work. I was curious to know about the real C++ . What am I missing? I program this way but I want to learn new techniques. I watch some video lessons on Youtube, even though I think they are weak, because they are what I have. Recommends some material where I can program with a more formal, more professional structure?
– Joao Pedro Martins de Paula
C doesn’t work that way either. You’re missing a lot, C+= is a totally different language that just happens to compile C codes. Virtually all C++ video classes are bad and teach you all wrong. Actually this is true for programming in general, there is very little with quality. I suggest looking for good books, good courses, but generally I do not indicate anything, has some indication in the description of tag. I just wouldn’t start doing things without understanding why it works or not. It will continue to follow cake recipes passed by third parties without learning.
– Maniero