I've written a recursive function for a project that deals with strings and I'm unsure about whether or not I can pass by reference with substrings. Here is a short snippet of what I am talking about:
I know what I have written isn't a very useful program, but theres a lot more going on.Code:void recursiveFunc(string& s) { .... // perform some stuff on the string here for (int x=0; x<s.length(); x++) { recursiveFunc(s.substr(x,s.length()-x)); } }
Now, I didn't think this would work at all because how does one send the address of a substring? But I tried in on MSVC++ and it worked, so I finished my project. Now I'm scared though, does anyone know if this is only a MSVC++ thing or would this work on any compiler? If I pass by value, the program runs WAY too slowly since the recursive function gets called millions of times. So I'm afraid that if other compilers complain about this that I need to rewrite it.



LinkBack URL
About LinkBacks


