检测this指针是否为空来提高健壮性

来源:互联网 发布:c语言sbit是什么意思 编辑:程序博客网 时间:2024/05/22 03:40

 

如题:

class C

{

public:

int function()

{

if( NULL == this )

{

return INVALID_HANDLE;

}

}

};

 

void main()

{

C * ptr = NULL;

 

int result = ptr->function();

 

if( INVALID_HANDLE == result )

{

//stop the following procedure and throw exception

}

}

 

原创粉丝点击