Calling member functions from one member function of the same class in C ++, objective C

Consider the following:

class A{ //data members void foo() { bar();//is this possible? or should you say this->bar() note that bar is not static } void bar() { } }//end of class A 

What do you call member functions from another? And how static functions affect the use of 'this'. Should functions be called on an object?

+4
source share
2 answers

Nawaz is right: 'this' is implicit. The only exception is if foo is a static function, because static functions do not have 'this'. In this case, you cannot use bar () if bar () is also a static function, and you cannot use this-> bar () at all.

+4
source
 bar();//is this possible? or should you say this->bar() 

this implicit. Thus, they are both equivalent. You can use any of them. But then I think, if just bar() enough, then why use this->bar() ?

Use this only if there is some ambiguity, otherwise use a simpler one!

+2
source

Source: https://habr.com/ru/post/1338804/


All Articles