-
January 19th, 2010, 07:20 PM
#16
Re: How to create a pointer to 'this'?
Originally Posted by Paul McKenzie
The OP is using more 'C' in their code than C++. Once you get into pointer to pointer, that is approaching 'C' coding, not C++.
Well, the OP is a C++ newbie and cannot be accused of being too much or too little C-isch, can he?
He's making heavy use of the this pointer though. If I understood you correctly you had a problem with that, didn't you?
-
January 19th, 2010, 08:05 PM
#17
Re: How to create a pointer to 'this'?
Originally Posted by Paul McKenzie
The OP is using more 'C' in their code than C++. Once you get into pointer to pointer, that is approaching 'C' coding, not C++.
You're inconsistent. First you accused the OP of using C++ like Java, and now you're accusing him of using C++ like C.
Make your mind up.
-
January 19th, 2010, 08:27 PM
#18
Re: How to create a pointer to 'this'?
Originally Posted by nuzzle
You're inconsistent. First you accused the OP of using C++ like Java
Hopefully, you are not trying to write C++ in the style of Java
There is no accusation there.
, and now you're accusing him of using C++ like C.
I will wait for the OP to respond. Thank you very much.
Regards,
Paul McKenzie
-
January 19th, 2010, 09:03 PM
#19
Re: How to create a pointer to 'this'?
Originally Posted by Paul McKenzie
I will wait for the OP to respond.
Why on earth would you do that?
Everything you've said in this thread is unrelated to anything the OP said.
-
January 19th, 2010, 09:11 PM
#20
Re: How to create a pointer to 'this'?
Originally Posted by nuzzle
Why on earth would you do that?
Because the OP started the thread. Why are you being belligerent for no apparent reason? Calm down.
Everything you've said in this thread is unrelated to anything the OP said.
OK, whatever you say...
Regards,
Paul McKenzie
-
January 19th, 2010, 09:33 PM
#21
Re: How to create a pointer to 'this'?
Originally Posted by nuzzle
Sure, this is implied within an object, but to be able to create a ** pointer to the object you first need to store this somewhere.
I still don't see where you need to have a ** pointer to this. If internally, it's implied. If external, I get the pointer when I new up the object. If I'm missing something, please illustrate with a code snippet.
-
January 19th, 2010, 09:50 PM
#22
Re: How to create a pointer to 'this'?
Originally Posted by Arjay
I still don't see where you need to have a ** pointer to this. If internally, it's implied. If external, I get the pointer when I new up the object. If I'm missing something, please illustrate with a code snippet.
I'll illustrate with a code snippet,
void main() {}
-
January 19th, 2010, 10:30 PM
#23
Re: How to create a pointer to 'this'?
Or with this little poem,
I strongly believe there is,
an implicit pointer called this.
There must be something this is pointing at,
I pray it is like that.
-
January 19th, 2010, 10:40 PM
#24
Re: How to create a pointer to 'this'?
Originally Posted by nuzzle
I'll illustrate with a code snippet,
void main() {}
I was hoping for a serious example.
-
January 19th, 2010, 10:54 PM
#25
Re: How to create a pointer to 'this'?
Originally Posted by Arjay
I was hoping for a serious example.
Well, not from me.
For the first time in my life I'me going to quit a forum without being banned.
Thank you all and good luck.
-
January 20th, 2010, 12:09 AM
#26
Re: How to create a pointer to 'this'?
Originally Posted by nuzzle
Well, not from me.
For the first time in my life I'me going to quit a forum without being banned.
Thank you all and good luck.
nuzzle,
you've been here far, far less than me,
but notice how you already have 2 green light reputation and I don't.
that means, you've done something right during your short stay here at the CG,
and that those people were helped by you.
The debate on this thread got little hot, no doubt about it.
But it is in this flame that all of us are forged,
for the reasons too hard to understand and too painful to accept,
to take the next hammering of the blacksmith.
So for the sake of people who might need your help in days to come,
I hope you stick around.
-
January 20th, 2010, 09:30 AM
#27
Re: How to create a pointer to 'this'?
Indeed! The impersonal nature of web-based debate can result in very "thick skin" when compared with face-to-face discussions. Don't take it personally.
-
January 20th, 2010, 01:10 PM
#28
Re: How to create a pointer to 'this'?
I seriously would like a code sample that demostrates the logic of having a pointer that points to the temporary r-value pointer of "this" :S. Of course the op doesn't need to do such a thing. he thinks the "this" is an object and not a pointer to the object itself. If anyone knows c++, they know how "this" is typically implemented. They know that it gets pushed on the stack as a parameter for the member function being called.
like
if( Kid.isChild() ) cout << "Yes" << endl;
would be
if( isChild( &Kid ) cout << "Yes" << endl;
that is psuedo code btw
That code makes sense why you shouldn't copy the address of where the pointers is located( &this ) since it is push on the stack and has limited life scope. It will no longer be valid after the member function is called. This is what Paul meant, i believe, when saying why would you need to do this?? It is just not logical
The op clearly thought that "this" was an object and not a pointer to the object itself
Again I seriously would like a code sample by Nuzzle that demostrates the logic of having a pointer that points to the temporary r-value pointer of "this" :S
Code:
List<PObject*>* tlist = postInits->data2For(type);
PObject** ptrtothis = &this;//non-lvalue in unary '&'
tlist->add(ptrtothis);
should be
Code:
List<PObject*>* tlist = postInits->data2For(type);
tlist->add( this )
also
Code:
TEMPLT void List<t>::add(const t* obj, int len){//len is 1 by default
if(totalSize-objectCount>len){
for(int i=0; i<len; i++){
contents[i+objectCount] = obj[i];
}
}else{
increaseSize(len);
for(int i=0; i<len; i++){
contents[i+objectCount] = obj[i];
}
}
objectCount+=len;
}
is redundant
Code:
TEMPLT void List<t>::add(const t* obj, int len){//len is 1 by default
if(totalSize-objectCount < len) increaseSize(len);
for(int i=0; i<len; i++)
contents[i+objectCount] = obj[i];
objectCount+=len;
}
<= is the opposite of >, but I used < because it made more sense....
the original code said totalSize-objectCount > len.., but let's say
(10 - 5 > 5) = (5 > 5) == false. if false, increaseSize( 5 ), but i think it should say
(10 - 5 >= 5) = (5 >= 5) == true. if false, increaseSize( 5 ). I think this is right if the totalSize is the total amount in which the list is allocated to hold?
Maybe I am wrong, but I don't see the full implementation either
Also Nuzzle, please relax some. No one here is going to flame you unless you're "very!" incorrect or touch a soft topic
Also feel free to correct me if I am wrong, but be sure you understand what I meant
Last edited by Joeman; May 24th, 2012 at 08:02 AM.
Reason: spelling
0100 0111 0110 1111 0110 0100 0010 0000 0110 1001 0111 0011 0010 0000 0110 0110 0110 1111 0111 0010
0110 0101 0111 0110 0110 0101 0111 0010 0010 0001 0010 0001 0000 0000 0000 0000 0000 0000 0000 0000
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|