a class function with if(this==NULL) test got compiled?

Posted by James on Stack Overflow See other posts from Stack Overflow or by James
Published on 2010-04-01T05:34:16Z Indexed on 2010/04/01 5:43 UTC
Read the original article Hit count: 274

Filed under:

I saw this code snippet during our lab and it actually compiles in MSVC2008 and G++.

void LinkList< class T >::Insert(T n)
{
if (this == NULL)
// some code here
}

As far as I know the this must not be null since you cannot call a class functions in c++ if it wasn't instantiated. Is this a valid code? if so what's the reason behind and where it can be useful?

© Stack Overflow or respective owner

Related posts about c++