Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POST sample string reference error #57

Closed
TcT2k opened this issue Oct 7, 2015 · 4 comments
Closed

POST sample string reference error #57

TcT2k opened this issue Oct 7, 2015 · 4 comments

Comments

@TcT2k
Copy link

TcT2k commented Oct 7, 2015

In the post sample this line uses the "user" constant, but in curl_pair the value is a reference:
curl_pair<CURLformoption,string> name_form(CURLFORM_COPYNAME,"user");

It only works when changed like this because of the scope of the string:
std::string fieldName = "user"; curl_pair<CURLformoption,string> name_form(CURLFORM_COPYNAME, fieldName);

Maybe curl_pair should copy the value? But at least the sample should be changed.

@JosephP91
Copy link
Owner

Hi @TcT2k !
another user found this issue, but I thought it was solved #18
Can you show me your code example? Thank you!

@wise86-android
Copy link
Contributor

I think that as the last comment on issue #18 say the problem is that you are keeping a reference to a temporary object (the string that is create when you pass a const char* to a function that require a string).
you have 2 option:
1 - use a constructor with an RValue (as write in issue #18)
2 - accept a string and not a string reference for force the compiler to copy it, and then move the string inside the pair class.

@TcT2k try if this commit fix the problem: wise86-android@be68022

@JosephP91
Copy link
Owner

@TcT2k is this issue solved?

@JosephP91
Copy link
Owner

@TcT2k any news?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants