Sunday, March 26, 2006

Gopal's static block example

Gopal's example at C++ Static Blocks with better syntax highlighting.


using namespace std;
class Static
{
private:
static vector values;
public:
Static ()
{
vector::iterator b = values.begin ();
for (; b != values.end (); b++)
{
cout << *b << endl;
}
}

class VectorInitializer
{
public:
VectorInitializer ()
{
Static::values.push_back (20);
Static::values.push_back (40);
Static::values.push_back (60);
}
};

friend class Static::VectorInitializer;
};

vector
Static::values;
static
Static::VectorInitializer
initalizer; //initializes the vector.

int
main (void)
{
Static
x;
}

2 comments:

Gops said...

This is awesome!
How can I do it?

Balbir Singh said...

Well, it is straight forward.


1. Download gvim
2. Enable Syntax Highlighting
3. Export to html
4 cut-copy-paste the html

Open source rocks :-)

Dynamic programming for the binomial coefficient

More fun things, this time with some visualisation of what happens when memoisation is used and what happens when we don't. I don'...