Skip to content

Instantly share code, notes, and snippets.

@benjamn
Created June 18, 2010 22:12
Show Gist options
  • Save benjamn/444300 to your computer and use it in GitHub Desktop.
Save benjamn/444300 to your computer and use it in GitHub Desktop.
#include <iostream>
using std::cout;
using std::endl;
int main() {
// Make the struct immutable so that public access is safe.
const struct AutoFoo {
~AutoFoo() {
// On destruction, do something with the members.
cout << x << ", " << y << endl;
}
int x, y;
} af = {
// Initialize the members without explicit constructor.
1, 2
};
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment