-->

C++ Tutorial : This pointer and static members

C++ Tutorial : This pointer and static members
    This Pointer
    The keyword this represents a pointer to the object whose member function is being executed. It is a pointer to the object itself.
    One of its uses can be to check if a parameter passed to a member function is the object itself. For example,
    // this
    #include <iostream>
    using namespace std;
    class CDummy {
    public:
    int isitme (CDummy& param);
    };
    int CDummy::isitme (CDummy& param)
    {
    if (&param == this) return true;
    else return false;
    }
    int main () {
    CDummy a;
    CDummy* b = &a;
    if ( b->isitme(a) )
    cout << "yes, &a is b";
    return 0;
    }

    Read more »
    fardi zayden
    @مرسلة بواسطة
    كاتب ومحرر اخبار اعمل في موقع دراسات تقنية .

    إرسال تعليق