[Solved] Error in dynamic allocation in C++ [closed]
[ad_1] You should allocate an array of chars, like so: char *CopyOf(const char *str) { char *copy = new char[strlen(str) + 1]; strcpy(copy, str); return copy; } Note that I used brackets, not parentheses. What you were doing with parentheses was initializing a single new char with the value strlen(str) + 1. Then you overran … Read more