Figure 2 Using a static class initializer

class testClass : public parentClass {
protected:
    int _value;             //internal data member
    int validate(int);      //validation function

    testClass( int input )    //constructor
    {   //validate input, set _value to result....
        _value = validate(input) == OK ? input : -1;
    }

public:
    ~testClass() { }        //destructor
    readfile( char * );     //other member function

    static testClass *Init( int input ) {
        testClass *objp = new testClass( input);

        if( objp->_value == -1 )  { //input invalid
            delete objp;        //deallocate object
            return NULL;        //return error
        }

        return objp;  //input OK
    }
};

//program "testprog.exe" ........

#include <iostream.h>

main( int argc, char **argv )
{
    testClass *test =
               testClass::Init( atoi( argy[1] ) );

    if( !test )     {
        cerr << "Object initialization failed\n";
        return 1;   //exit, return error
    }

    //continue normal program operation ....
        ..
        ..
    test->readfile( argv[2] ); //access member func
        ..
        ..
    delete test;
    return 0;
}
/* ----- End of File ------------------------------ */