online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
/****************************************************************************** Welcome to GDB Online. GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl, C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog. Code, Compile, Run and Debug online from anywhere in world. *******************************************************************************/ #include <iostream> #include <iomanip> #include <assert.h> #include <stdlib.h> #include <string.h> #include <new> using namespace std; class Charstr { protected: char _objname [32]; char *_str; public: Charstr(); Charstr(char *inname, char *instr); Charstr(char *inname){ cout << "One-Arg Charstr Constructor for " << inname << endl; assert(strlen(inname) < 32); strcpy(_objname, inname); _str = 0;} /*Charstr& operator=(Charstr& inobj){ delete _str; _str=new char[strlen(inobj._str)+1]; strcpy(_str,inobj._str); return *this; }*/ ~Charstr(); Charstr(Charstr& obj){ cout<<"calling copy constructor for "<<obj._objname<<endl; _str= new char[strlen(obj._str)+1]; strcpy(_str,obj._str); strcpy(_objname,obj._objname); } Charstr reverse(); friend ostream &operator << (ostream &stream, Charstr &inobj); }; void exhausted() { cout << "Free store is exhausted!" << endl; exit(0);} Charstr::Charstr(){_str = 0;} Charstr::Charstr(char *inname, char *instr){ cout << "Two-Arg Charstr Constructor for " << inname << endl; assert(instr); _str=new char[strlen(instr) + 1]; strcpy(_str, instr); assert(strlen(inname) < 32); strcpy(_objname, inname);} Charstr::~Charstr() {cout << "Charstr destructor for " << _objname << endl; cout << "Freeing pointer " << (void *)_str << endl; delete _str; } ostream &operator << (ostream &stream, Charstr &inobj) { stream << "obj:" << inobj._objname << endl; stream << "str: " << inobj._str << endl; return stream; } Charstr Charstr::reverse() { Charstr temp; int len=0,i=0,j=0; cout << "reversing object"<<_objname << endl; strcpy(temp._objname, "temp"); len = strlen(_str); temp._str = new char[len + 1]; for (i=(len-1),j=0; j<len; i--, j++) temp._str[j] = _str[i]; temp._str[len] = '\0'; cout << "returning temp." << endl; return temp; } void func1(Charstr inobj) { cout << inobj; } int main() { Charstr c1("c1","Mike"), c2("c2","Jack"); set_new_handler(exhausted); func1(c1); func1(c2); func1(c1); Charstr c3("c3"); c3 = c2.reverse(); cout << "After reverse, printing c3" << endl; cout<<c3;}

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue