Skip to content

Instantly share code, notes, and snippets.

@t-mat
Created October 26, 2011 17:14
Show Gist options
  • Save t-mat/1317043 to your computer and use it in GitHub Desktop.
Save t-mat/1317043 to your computer and use it in GitHub Desktop.
C++ scoped object trick
#include <stdio.h>
class A {
public:
A() { printf("A : begin\n"); }
~A() { printf("A : end\n"); }
operator bool() const { return true; }
};
#define SCOPED_OBJ() if(A a = A())
int main() {
SCOPED_OBJ() {
printf("in scope (1)\n");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment