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;
}
Post a Comment