Skip to content

Instantly share code, notes, and snippets.

@martinky
Last active March 23, 2021 11:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martinky/6b395a5d9fc16ba22e9b1f7353ad5973 to your computer and use it in GitHub Desktop.
Save martinky/6b395a5d9fc16ba22e9b1f7353ad5973 to your computer and use it in GitHub Desktop.
Dummy helper struct that helps to debug when C++ objects get created, copied and destroyed.
#pragma once
/*
Dummy struct that prints a line whenever it is constructed, copied, moved or destructed.
*/
struct dummy {
int val;
dummy() : val(0) { printf("dummy() def ctor\n"); }
dummy(int v) : val(v) { printf("dummy(%d) ctor\n", val); }
dummy(const dummy &d) : val(d.val) { printf("dummy(%d) copy ctor\n", val); }
dummy(dummy &&d) : val(d.val) { printf("dummy(%d) move ctor\n", val); d.val = 0; }
~dummy() { printf("~dummy(%d) dtor\n", val); val = -1; }
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment