Last active
March 23, 2021 11:15
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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