判断类指针是否有效(VC)

#ifndef __TCHKVALIDIMPL_H__
#define __TCHKVALIDIMPL_H__

#pragma once

template 
class TChkValidImpl
{
public:
	TChkValidImpl()
	{
		__chk_sum_id__ = chksumid;
	}
	virtual ~TChkValidImpl()
	{
		__chk_sum_id__ = 0xcdcdcdcd;
	}

	enum VALID_OP_CODE{VOP_READ=0x1,VOP_WRITE=0x2,VOP_ALL=0x3};

	bool IsValid(char op = VOP_ALL)
	{
		if( (op & VOP_READ) == VOP_READ
			&& IsBadReadPtr(this, sizeof(T)) )
			return false;

		if( (op & VOP_WRITE) == VOP_WRITE
			&& IsBadWritePtr(this, sizeof(T)) )
			return false;

		return (__chk_sum_id__ == chksumid);
	}

public:
	unsigned int __chk_sum_id__;
};


#endif // __TCHKVALIDIMPL_H__


你可能感兴趣的:(判断类指针是否有效(VC))