Home > Enterprise >  Debugger is not stepping into expected function
Debugger is not stepping into expected function

Time:07-06

#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");
    
}

debugger_img_1

debugger_img_2

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.

  • Related