Note that there are some explanatory texts on larger screens.

plurals
  1. POmunmap_chunk(): invalid pointer: 0x00007fffbef49d90 in a recursive function
    primarykey
    data
    text
    <p>I am new to programming, so even after trying to google this error I couldn't find anything that was either relevant to my project or was simple enough for me to follow.</p> <p>I have to make a function that reverses a string iteratively, then another function which does so recursively. The iterative function works perfectly fine:</p> <pre><code>string reverse(string str_input) { string result = ""; //initialize a blank string to hold reversed string for(int i = (str_input.length() - 1); i &gt;= 0; i--) { result += str_input.substr(i,1); //concatenates the string backwards } return result; </code></pre> <p>However when I tried to make it recursive, I got an invalid pointer error. I've copied my main I'm using for testing and the other function here: string reverse_rec(string str_input, string result, int input_length);</p> <pre><code>int main() { string str_input = "hello"; int input_length = (str_input.length() - 1); string result = ""; cout&lt;&lt; reverse_rec(str_input, result, input_length) &lt;&lt; endl; return 0; } string reverse_rec(string str_input, string result, int input_length) { if(input_length &lt;= 0) { return result; } else { reverse_rec(str_input, result += str_input.substr(input_length,1), --input_length); } } </code></pre> <p>Does anyone have any hints as to what might be causing this error? From what I've read, most of the people got this error when trying to delete things, but I don't seem to be deleting anything in this program...</p> <p>Note: We have to do this by concatenating substrings and not by using arrays, as we haven't covered arrays in depth yet.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload