無いとも言えないと思います。
http://pc5.2ch.net/test/read.cgi/tech/1091185216/821
#define STATIC_THIS_DECL() static void __tmpmethod(); struct __tmp { __tmp() { __tmpmethod(); } }; static __tmp __tmpval #define STATIC_THIS(klass, func) void klass::__tmpmethod() { func; }; klass::__tmp klass::__tmpval; #define STATIC_DTHIS_DECL() static void __tmpdmethod(); struct __tmpd { ~__tmpd() { __tmpdmethod(); } }; static __tmpd __tmpdval #define STATIC_DTHIS(klass, func) void klass::__tmpdmethod() { func; }; klass::__tmpd klass::__tmpdval; // ここからがクライアントコードのヘッダね #includeclass C { public: STATIC_THIS_DECL(); STATIC_DTHIS_DECL(); static int i; }; // ここからがクライアントコードのソースね STATIC_THIS(C, { i = 123; printf("static this\n"); }); STATIC_DTHIS(C, { printf("static ~this i=%d\n", i); }); int C::i; int main() { printf("hello\n"); printf("%d\n", C::i); return 0; }
実行結果
static this hello 123 static ~this i=123