DontInitialize Struct Reference

Dummy structure. More...

List of all members.


Detailed Description

Dummy structure.

Some classes might be heavy to initialize, and named constructors (static functions that return an instance of the class) need some way to create an instance of the class without filling out the values. We use this dummy structure to code a constructor that does not initialize the members:

        class A
        {
                int * _x;
        public:
                A() {_x = new int[10000000000000000000000];}  // I know, I know ... but I'm making a point
                A( DontInitialize ) {}
                static A giveMeAnA(const int x)         // named constructor
                {
                        A a( DontInitializeMe );            // it won't exhaust the memory
                        a._x = new int[x];
                        return a;
                }
        };

Back to SmartWin website
SourceForge.net Logo