some time it would make code easier to check if this is NULL.
For instance, instead of :
Expand|Select|Wrap|Line Numbers
-
class foo
{
- int x ;
- void bar () { cout << "my x is " << x ;} // crashes if this is null !
- } ;foo * f = ... ;
- if (f) f->bar() ; // so check before to call !
Expand|Select|Wrap|Line Numbers
-
class foo
{
- int x ;
- void bar () { if (this) cout << "my x is " << x ;} // won't crash if this is null
- } ;foo * f = ... ;
- f->bar() ; // call and don't care !
Will it always work ?
What if the method 'bar' is virtual ?
Is it compiler dependant ?
Is there some thing about this in some holly book of c++ ?
thanks !
Gaspos