Skip to content

Instantly share code, notes, and snippets.

@jamescurran
Created June 25, 2013 13:33
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 jamescurran/5858463 to your computer and use it in GitHub Desktop.
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/
#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