what does "this" mean?
-
I just encountered this "this" in a sample code. Can anyone explain what it means?. _param->_this = this; Is the "this" an operator? Thanks. Deepak Samuel
-
I just encountered this "this" in a sample code. Can anyone explain what it means?. _param->_this = this; Is the "this" an operator? Thanks. Deepak Samuel
The
this
pointer refers to the object in which it is invoked.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
-
I just encountered this "this" in a sample code. Can anyone explain what it means?. _param->_this = this; Is the "this" an operator? Thanks. Deepak Samuel
this
is the current object instance. you can do stuff like that...class CClass
{
int i;
void Method();
}void CClass::Method()
{
// equivalent.
this->i = 1;
i = 1;
}or if you you want to pass yourself to another class or method :
...
CPaintDC dc(this);
...
Maximilien Lincourt Your Head A Splode - Strong Bad
-
I just encountered this "this" in a sample code. Can anyone explain what it means?. _param->_this = this; Is the "this" an operator? Thanks. Deepak Samuel
"this" is introduced so the compiler could make the difference between members of the class and members of another object. eg. if you would do this:
public void SetSomeInt(int input){ input = input; }
then the compiler probably would complain. which one is the parameter and which one is the variable of the class? if you do this:public void SetSomeInt(int input){ this->input = input; }
it will probably work. It's just a pointer to the Object itself. "If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix -
I just encountered this "this" in a sample code. Can anyone explain what it means?. _param->_this = this; Is the "this" an operator? Thanks. Deepak Samuel
"this" is introduced so the compiler could make the difference between members of the class and members of another object. eg. if you would do this:
public void SetSomeInt(int input){ input = input; }
then the compiler probably would complain. which one is the parameter and which one is the variable of the class? if you do this:public void SetSomeInt(int input){ this->input = input; }
it will probably work. It's just a pointer to the Object itself. (and that's the reason why you can't use it in static functions) "If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix -
"this" is introduced so the compiler could make the difference between members of the class and members of another object. eg. if you would do this:
public void SetSomeInt(int input){ input = input; }
then the compiler probably would complain. which one is the parameter and which one is the variable of the class? if you do this:public void SetSomeInt(int input){ this->input = input; }
it will probably work. It's just a pointer to the Object itself. (and that's the reason why you can't use it in static functions) "If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi HendrixI would advise that you *DO NOT* use the same naming convention for local function variables and member variables. It can, and will, always lead to confusion and mistakes. Ant. I'm hard, yet soft.
I'm coloured, yet clear.
I'm fruity and sweet.
I'm jelly, what am I? Muse on it further, I shall return! - David Williams (Little Britain) -
I just encountered this "this" in a sample code. Can anyone explain what it means?. _param->_this = this; Is the "this" an operator? Thanks. Deepak Samuel
you've been having many good answers, so i won't add more about the
this
pointer you're asking for. i'd just like to tell you thatthis
is an important part of the C++ language, and you'd so better get a reference of the language to learn about it... there are many books on the subject, and also the MSDN treats about it. cheers,:rose:
TOXCCT >>> GEII power
-
I would advise that you *DO NOT* use the same naming convention for local function variables and member variables. It can, and will, always lead to confusion and mistakes. Ant. I'm hard, yet soft.
I'm coloured, yet clear.
I'm fruity and sweet.
I'm jelly, what am I? Muse on it further, I shall return! - David Williams (Little Britain) -
I would advise that you *DO NOT* use the same naming convention for local function variables and member variables. It can, and will, always lead to confusion and mistakes. Ant. I'm hard, yet soft.
I'm coloured, yet clear.
I'm fruity and sweet.
I'm jelly, what am I? Muse on it further, I shall return! - David Williams (Little Britain)