C++ How to take the string of the get method of a class x and concatenate with a class y string?

Asked

Viewed 63 times

1

I am programming a code in Qt(C++) and I need to take values from the client class in the menu class (which I do not inherit from client) and concatenate into a string to print on the screen. follows the code:

cliente* cl = new cliente();

Later in the code I set values for the customer and then arrived at the part that is not working:

string g = "Dados do cliente: \n   Nome: " + cl->getNome() + "\n   Email: " + cl->getEmail() + "    Telefone: " + cl->getTelefone() + "\n   Endereço: " + cl->getEndereco() + "\n   Carro : " + cl->getCarro() + ", " + cl->getAnoCarro() + "    Placa: " + cl->getPlaca() + "\n";

The error is Segmentation fault. The way my getters is this for everyone(are all string):

const string &cliente::getPlaca() const {return placa;}

Does anyone have any idea how to fix?

  • All methods are strings ? Including getTelefone ? You can put a Minimum, Complete and Verifiable Example of the problem ?

  • Yes, all are string, converted all to string to save.

  • An example: I have the client class, then in the menu class I imported client. h, and I created a new client(). At one point I set values for this client of mine, and I ran into this problem: I can’t format a string using client data, from segmentation failure.

  • But it makes a mistake to compile ? Or just from the error to run ?

  • Just running really, compile normal

  • You can put a Minimum, Complete and Verifiable example of the problem ?

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.