Why is there a performance warning on cast pointer to bool?

前端 未结 6 1946
花落未央
花落未央 2020-12-09 01:14

Extends.

I thought I was being cool when I did something like:

bool hasParent()
{
  return this->parentNode ;
}

Even with a (bool) cast, the

6条回答
  •  执念已碎
    2020-12-09 02:04

    It would be more efficient to write:

    bool hasParent()
    {
        return  this->parentNode != NULL;
    }
    

提交回复
热议问题