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 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 :-)

Ranking and Unranking permutations

I've been a big fan of Skiena's Algorithm Design Manual , I recently found my first edition of the book (although I own the third ed...