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