Skip to content

Instantly share code, notes, and snippets.

@stormbrew
Created July 20, 2012 01:16
Show Gist options
  • Save stormbrew/3148047 to your computer and use it in GitHub Desktop.
Save stormbrew/3148047 to your computer and use it in GitHub Desktop.
#include <string>
#include <cstdio>
using namespace std;
class X
{
public:
string str;
X(const string &s) : str(s) { printf("Constructor %s 0x%p\n", str.c_str(), this); }
~X() { printf("Destructor %s 0x%p\n", str.c_str(), this); }
X x(const string &s) const { X z("scope"); printf("X::x() %s->%s 0x%p\n", str.c_str(), s.c_str(), this); return X(s); }
};
void func(const X &x)
{
printf("func\n");
}
int main()
{
func(X("outer").x("inner1").x("inner2"));
}
Constructor outer 0x0x7fff299bbd90
Constructor scope 0x0x7fff299bbd40
X::x() outer->inner1 0x0x7fff299bbd90
Constructor inner1 0x0x7fff299bbdb0
Destructor scope 0x0x7fff299bbd40
Constructor scope 0x0x7fff299bbd40
X::x() inner1->inner2 0x0x7fff299bbdb0
Constructor inner2 0x0x7fff299bbdd0
Destructor scope 0x0x7fff299bbd40
func
Destructor inner2 0x0x7fff299bbdd0
Destructor inner1 0x0x7fff299bbdb0
Destructor outer 0x0x7fff299bbd90
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment