Page 2 of 2

Re: Is it possible to use a string as an objects name?

Posted: Sun Nov 30, 2008 8:59 am
by Arce
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;

Re: Is it possible to use a string as an objects name?

Posted: Sun Nov 30, 2008 10:56 am
by avansc
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;
}

Re: Is it possible to use a string as an objects name?

Posted: Sun Nov 30, 2008 11:22 am
by Arce
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.
Haha, great idea. I'll do a shitload of that, making this necessary....Then wait for her to say something. XDD

Re: Is it possible to use a string as an objects name?

Posted: Sun Nov 30, 2008 11:40 am
by avansc
Arce wrote:
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.
Haha, great idea. I'll do a shitload of that, making this necessary....Then wait for her to say something. XDD
in my earlier days when i thought i knew everything i was a little shit to all my CSC teachers (like highschool and first year of college)
i think that was when i wanted to prove something to them, i would allways get them in a situation and then make them look like idiots infrom of the class.

take my advice, be a brown noser and dont try an piss teachers off. its not worth it, i can vouch for it.
just think of it this way, in 10 years you will be making lots of money, have a wife, possibly a lady on the side.
and the teacher will still be dealing with snot nosed kids.

Re: Is it possible to use a string as an objects name?

Posted: Sun Nov 30, 2008 1:12 pm
by dandymcgee
avansc wrote:have a wife, possibly a lady on the side.
:lol: