C++ has `local'!

Not exactly Perl post, but very related!

The code:


#include <iostream>
#include <string>

using namespace std;

template<class T>
struct clocal {
clocal(T& p) : pvar(p), pval(p) {}
clocal& operator=(const T& val) { pvar=val; return *this; }
~clocal() { pvar=pval; }
T& pvar;
T pval;
};

string s = "global";
int i = 0;

void print()
{
cout << s << ", " << i <&l…

About maxim4d

user-pic Occasional notes about Perl.