0

I have constructor for my base class named BaseClass

BaseClass::BaseClass(BaseClass* parent)
{
    if (parent != 0)
    {
        parent->children.push_back(this);
    }
    this->parent = parent;
    ready = 1;
}

This method checks if pointer to parent object is 0 or null and sets it as parent of current object and after it sets ready state of current object to 1.

I read articles where author used nullptr keyword in pointer declaration. C++ also allows me to use 0 to declare null pointer but should I use nullptr keyword instead of 0 in my constructor for example if I pass null pointer to it as 0?

WideWood
  • 549
  • 5
  • 13
  • Maybe this will help clarify the use of nullptr. [Is nullptr in C++ the same as null in C#?](https://stackoverflow.com/questions/22550916/is-nullptr-in-c-the-same-as-null-in-c) – Nicholas Hunter Apr 24 '21 at 16:36
  • Well it seems ```nullptr``` is more correct because sometimes compiler can not understand what 0 is, is this integer or null pointer?. – WideWood Apr 24 '21 at 16:47

0 Answers0