B
Bedevere13
I made the following class in order to validate my objects:
class Validation
{
public:
inline bool bIsValid(void) const { return (this && m_uiValidation ==
0x4321);}
inline void Verify(void) const {if (!bIsValid()) throw
std::string("Accessing invalid Object"); }
Validation(void) {Validate();}
virtual ~Validation(void) {Invalidate();}
protected:
inline void Validate(void) {m_uiValidation = 0x4321;}
inline void Invalidate(void) {m_uiValidation = 0;}
private:
unsigned int m_uiValidation;
};
Before I use an object, I will check bIsValid(), which is good for
catching NULL pointers, but I have gotten some seg faults from the
bIsValid() code when there is a bad pointer. Does anyone know how to
not die in that function if the this pointer is bad and to just return
false so the calling code can deal with it?
class Validation
{
public:
inline bool bIsValid(void) const { return (this && m_uiValidation ==
0x4321);}
inline void Verify(void) const {if (!bIsValid()) throw
std::string("Accessing invalid Object"); }
Validation(void) {Validate();}
virtual ~Validation(void) {Invalidate();}
protected:
inline void Validate(void) {m_uiValidation = 0x4321;}
inline void Invalidate(void) {m_uiValidation = 0;}
private:
unsigned int m_uiValidation;
};
Before I use an object, I will check bIsValid(), which is good for
catching NULL pointers, but I have gotten some seg faults from the
bIsValid() code when there is a bad pointer. Does anyone know how to
not die in that function if the this pointer is bad and to just return
false so the calling code can deal with it?