943,697 Members | Top Members by Rank

Ad:
Jul 4th, 2009
0

"this" keyword in OOP

Expand Post »
Hello
In many OOP languages "this"(or something similar) is used to point to current object. But i think its an object by itself. Here is what i found" polymorphic object which can point in different times to different object`s types"
I like to get some more information about this maybe some science article.
Thank you in advance.
Similar Threads
Reputation Points: 46
Solved Threads: 0
Light Poster
yakovm is offline Offline
27 posts
since May 2009
Jul 4th, 2009
0

Re: "this" keyword in OOP

What more information could there possibly be??? As you already stated its just a pointer to the current c++ class object.

For example, here's the output of the following in c++. It shows that the this pointer is the same in both child and parent.
A:  this = 2afc38
B:  this = 2afc38
Press any key to continue . . .
class A
{
public:
    A() 
    {
        x = 0;
    cout << "A:  this = " << hex << (unsigned int)this << "\n";
    }
private:
    int x;
};

class B : public A
{
public:
    B()
    {
        y = 0;
        cout << "B:  this = " << hex << (unsigned int)this << "\n";
    }
private:
    int y;
};


int main(int argc, char* argv[])
{
    B b;
}
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is online now Online
21,950 posts
since Aug 2005
Jul 4th, 2009
0

Re: "this" keyword in OOP

Its just a Compilers way of saying "The main object under my concern right now is this" ,as AncientDragon has stated its just a pointer which is maintained completely by compiler which the user cannot modify,but can make use of it foir referencing the current object.For more info try these 1 2.
Last edited by csurfer; Jul 4th, 2009 at 11:53 pm.
Reputation Points: 485
Solved Threads: 88
Posting Pro
csurfer is offline Offline
564 posts
since Jan 2009
Jul 7th, 2009
0

Re: "this" keyword in OOP

In Java you can think of 'this' as being the same thing as the name of the Object. So if you are in the class MyClass, 'this' is your MyClass Object.
Reputation Points: 874
Solved Threads: 352
Posting Maven
BestJewSinceJC is offline Offline
2,758 posts
since Sep 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Computer Science Forum Timeline: Need help with a paper sketch
Next Thread in Computer Science Forum Timeline: New Ideas





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC