Arce wrote:Yes, you would need the "->".
It's the equiv of doing
*(this).whatever = someshit;
(the parenthesis are necessary)
im not exactly sure now. but i think if its a pointer you do this->bla and if its a reference its this.bla.
Isn't it always a pointer to current object? Or is there some way to have the compiler return this as a reference?
I tried to make the use of "this" as a standard, but I was out voted.
My teacher counted off points in "code clarity" on a test this one time because "unnecessary use of 'this' "
Bitch, delete this;
yeah, i messed up, if you are writing the member fuctions of the class it will allways be ->
but if you make a normal class variable you can access unprotected (ie: public) variables and functions with the object.function, but if you have a pointer to that class object (ie: classname *variablename) you have to use the "->" opperand. there are other ways to.
ps: there is no such thing as using the "this" keyword to much, exept maybe if you get into a situation where its something like this.this.function/variable
but that will only result from bad programming. i would take that teacher on. use of the "this" key word is encouraged because it helps people who might review your code to know what variables you use.
i use the "this" keyword allot because im particular about function parameter names.
if an object has a variable pair X and Y, i will use the same variable names in the function parameters.
Code: Select all
void setXY(int X, int Y)
{
this->X = X;
this->Y = Y;
}