G
Generic Usenet Account
I am going through some legacy code that has an "isNull()" method
defined on certain classes. I can see that this can be a good way to
eliminate certain types of crashes, by making this the first call in a
method (and bailing out immediately if it is true). However, if this
is such a good idea, why is it not common industry practice?
Mohan
/////////////// Sample source code //////////////
#include <iostream>
using namespace std;
class SampleClass
{
public:
SampleClass(int i):attrVal(i) {}
~SampleClass(){}
void printIt()
{
if(!isNull())
cout << "My attribute value is " << attrVal << endl;
else
cout << "I am NULL" << endl;
}
bool isNull() {return this == 0;}
protected:
int attrVal;
};
main()
{
SampleClass *ptr = NULL;
ptr->printIt();
}
defined on certain classes. I can see that this can be a good way to
eliminate certain types of crashes, by making this the first call in a
method (and bailing out immediately if it is true). However, if this
is such a good idea, why is it not common industry practice?
Mohan
/////////////// Sample source code //////////////
#include <iostream>
using namespace std;
class SampleClass
{
public:
SampleClass(int i):attrVal(i) {}
~SampleClass(){}
void printIt()
{
if(!isNull())
cout << "My attribute value is " << attrVal << endl;
else
cout << "I am NULL" << endl;
}
bool isNull() {return this == 0;}
protected:
int attrVal;
};
main()
{
SampleClass *ptr = NULL;
ptr->printIt();
}