"this" keyword in OOP

Please support our Computer Science advertiser: Learn about neural networks and artificial intelligence.
Reply

Join Date: May 2009
Posts: 12
Reputation: yakovm is on a distinguished road 
Solved Threads: 0
yakovm yakovm is offline Offline
Newbie Poster

"this" keyword in OOP

 
0
  #1
Jul 4th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,151
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1435
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: "this" keyword in OOP

 
0
  #2
Jul 4th, 2009
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;
}
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 476
Reputation: csurfer is just really nice csurfer is just really nice csurfer is just really nice csurfer is just really nice csurfer is just really nice 
Solved Threads: 75
csurfer's Avatar
csurfer csurfer is offline Offline
Posting Pro in Training

Re: "this" keyword in OOP

 
0
  #3
Jul 4th, 2009
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.
I Surf in "C"....
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 1,529
Reputation: BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all 
Solved Threads: 190
BestJewSinceJC BestJewSinceJC is offline Offline
Posting Virtuoso

Re: "this" keyword in OOP

 
0
  #4
Jul 7th, 2009
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.
I am so hungry. :(
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Computer Science Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC