Home > Back-end >  Why this pointer is valid only in a non-static member function?
Why this pointer is valid only in a non-static member function?

Time:10-09

Why this pointer in c + + is valid only in a non-static member function?

CodePudding user response:

Because there is no object instance for a static member function, can be called, so, can't let it use this pointer,
Because the object does not yet exist, this can't be used;
Non-static function, the object must be created, so it can use this, said object from already,
Experience experience can understand more,

CodePudding user response:

Static member function call, there is no transfer of this pointer, a static member function is like ordinary C function,
  • Related