Skip to main content
added 142 characters in body
Source Link
John3136
  • 29.3k
  • 4
  • 55
  • 77

Look up "pass by value" and "pass by reference" - you have "pass by value" but you are expecting "pass by reference"

In C++: void convert(string& response) {

In your case things are slightly "odd" because as pointed out in the comments by @NeilLocketz, you have a global response, the local response in the method - which is actually the global one since you use that as the calling parameter. If you want to do things properly, you probably don't want response to be global.

Note that the accepted answer still has more memory copies than this. The real key is to understand pass by value and pass by reference and use whichever one is appropriate to your circumstances.

Look up "pass by value" and "pass by reference" - you have "pass by value" but you are expecting "pass by reference"

In C++: void convert(string& response) {

In your case things are slightly "odd" because as pointed out in the comments by @NeilLocketz, you have a global response, the local response in the method - which is actually the global one since you use that as the calling parameter. If you want to do things properly, you probably don't want response to be global.

Look up "pass by value" and "pass by reference" - you have "pass by value" but you are expecting "pass by reference"

In C++: void convert(string& response) {

In your case things are slightly "odd" because as pointed out in the comments by @NeilLocketz, you have a global response, the local response in the method - which is actually the global one since you use that as the calling parameter. If you want to do things properly, you probably don't want response to be global.

Note that the accepted answer still has more memory copies than this. The real key is to understand pass by value and pass by reference and use whichever one is appropriate to your circumstances.

added 325 characters in body
Source Link
John3136
  • 29.3k
  • 4
  • 55
  • 77

Look up "pass by value" and "pass by reference" - you have "pass by value" but you are expecting "pass by reference"

In C++: void convert(string& response) {

In your case things are slightly "odd" because as pointed out in the comments by @NeilLocketz, you have a global response, the local response in the method - which is actually the global one since you use that as the calling parameter. If you want to do things properly, you probably don't want response to be global.

Look up "pass by value" and "pass by reference" - you have "pass by value" but you are expecting "pass by reference"

In C++: void convert(string& response) {

Look up "pass by value" and "pass by reference" - you have "pass by value" but you are expecting "pass by reference"

In C++: void convert(string& response) {

In your case things are slightly "odd" because as pointed out in the comments by @NeilLocketz, you have a global response, the local response in the method - which is actually the global one since you use that as the calling parameter. If you want to do things properly, you probably don't want response to be global.

Source Link
John3136
  • 29.3k
  • 4
  • 55
  • 77

Look up "pass by value" and "pass by reference" - you have "pass by value" but you are expecting "pass by reference"

In C++: void convert(string& response) {