#include<iostream>
#include<string>
using namespace std;
void reverse(string s){
if(s.length()==0){ //base case
return;
}
string ros=s.substr(1);
reverse(ros);
cout<<s[0];
}
int main(){
reverse("binod");
}
PFA, The debugger is supposed to step into the reverse() function. But it is opening these tabs.
CodePudding user response:
The debugger is stepping into the std::string(const char*)
constructor. Your code calls this implicitly before calling reverse
because you pass "binod"
(which effectively has type const char*
) to a function expecting a std::string
.
There's nothing wrong here, it's not the wrong function, just a function you didn't realise was being called. Just step out and then step in again.
Side note: Visual Studio's debugger has the 'Just My Code!' feature which, when enabled, means the debugger only steps into code you wrote. Can be a useful time saver.