1

Topic: It is correct to return the pointer on local object of function?

Wrote such useful function:

std:: string ConvertQStringToString (const QString Source)
{
return Source.toUtf8 ().constData ();
}

Me disturbs that constData () returns the pointer, on the LOCAL array created by function toUtf8 (). After all it will be deleted at an output from function and not the fact that this code will always work truly. Correctly I think?
If so to write incorrectly, to transfer a line the receiver as the second parameter?

2

Re: It is correct to return the pointer on local object of function?

AlekseySQL wrote:

Correctly I think?

Incorrectly. Reset goes on value, instead of the pointer or the link. The data will be copied
In  storage.

3

Re: It is correct to return the pointer on local object of function?

Thanks!

4

Re: It is correct to return the pointer on local object of function?

Generally in QString there is an intrinsic function
IN std:: string...

AlekseySQL wrote:

Wrote such useful function:
[code]
std:: string ConvertQStringToString (const QString Source)
{
return Source.toUtf8 ().constData ();
}
[/code]
Me disturbs that constData () returns the pointer, on the LOCAL array created by function toUtf8 (). After all it will be deleted at an output from function and not the fact that this code will always work truly. Correctly I think?
?

Incorrectly.
Array that local, but also from it should TO an output from function
To be generated an output line string, and  to return from function.
Therefore in this code all  in this sense.
And here is how you are going to store utf8 in std:: string, not clearly.
It certainly is possible, but...
[code]
If so to write incorrectly, to transfer a line the receiver as the second parameter?

It just would be upwards idiocy