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

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

User avatar
Arce
Jealous Self-Righteous Prick
Jealous Self-Righteous Prick
Posts: 2153
Joined: Mon Jul 10, 2006 9:29 pm

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

Post 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;
<qpHalcy0n> decided to paint the office, now i'm high and my hands hurt
User avatar
avansc
Respected Programmer
Respected Programmer
Posts: 1708
Joined: Sun Nov 02, 2008 6:29 pm

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

Post 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;
}
Some person, "I have a black belt in karate"
Dad, "Yea well I have a fan belt in street fighting"
User avatar
Arce
Jealous Self-Righteous Prick
Jealous Self-Righteous Prick
Posts: 2153
Joined: Mon Jul 10, 2006 9:29 pm

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

Post 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
<qpHalcy0n> decided to paint the office, now i'm high and my hands hurt
User avatar
avansc
Respected Programmer
Respected Programmer
Posts: 1708
Joined: Sun Nov 02, 2008 6:29 pm

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

Post 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.
Some person, "I have a black belt in karate"
Dad, "Yea well I have a fan belt in street fighting"
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

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

Post by dandymcgee »

avansc wrote:have a wife, possibly a lady on the side.
:lol:
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
Post Reply