online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
#include <iostream> using namespace std; // Imagine this is some object that can // internally store a pointer to a parent object class A { public: // The constructor without "explicit" -- add to see what happens A(A *pA = nullptr) { pParent = pA; } // Just prints out the values of the object's fields void Print() { cout << "someProp: " << someProp << ", "; cout << "parent: { "; if (pParent) pParent->Print(); else cout << "null"; cout << " }"; } // Same as Print(), but adds a newline void PrintLine() { Print(); cout << endl; } // I'll just make these public for convenience. // E.g. I wanted to set someProp in main(), so that we can // distinguish different instances int someProp = 0; A* pParent = nullptr; }; // Some function that takes an A void Foo(A a) { cout << "a in Foo(a): " << endl; a.PrintLine(); } int main() { A a1; a1.someProp = 123; cout << "a1: " << endl; a1.PrintLine(); A *pA = &a1; A a2 = pA; // implicit "conversion" happens here cout << "a2: " << endl; a2.PrintLine(); Foo(pA); // implicit "conversion" happens here too return 0; }

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