Created
June 25, 2013 13:33
-
-
Save jamescurran/5858463 to your computer and use it in GitHub Desktop.
C++ version of code from Eric Lippert's blog post "Construction destruction" http://ericlippert.com/2013/06/10/construction-destruction/
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
#include "stdafx.h" | |
class SideEffects | |
{ | |
public: | |
static void Alpha() { printf("Alpha\n"); } | |
static void Bravo() { printf("Bravo\n");} | |
static void Charlie() { printf("Charlie\n"); } | |
static inline void M(); | |
}; | |
class Foo | |
{ | |
private: | |
int x; | |
int y; | |
public: | |
Foo(int x, int y) | |
{ | |
this->x = x; | |
this->y = y; | |
SideEffects::Alpha(); // Notice: does not use "this" | |
} | |
~Foo() | |
{ | |
SideEffects::Charlie(); | |
} | |
}; | |
void SideEffects::M() | |
{ | |
Foo foo = Foo(1, 2); | |
Bravo(); | |
} | |
int _tmain(int argc, _TCHAR* argv[]) | |
{ | |
SideEffects::M(); | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment