Skip to content

Instantly share code, notes, and snippets.

@martinky
Last active Mar 23, 2021
Embed
What would you like to do?
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