CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 28 of 28
  1. #16
    Join Date
    May 2009
    Posts
    2,413

    Re: How to create a pointer to 'this'?

    Quote Originally Posted by Paul McKenzie View Post
    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?

  2. #17
    Join Date
    May 2009
    Posts
    2,413

    Re: How to create a pointer to 'this'?

    Quote Originally Posted by Paul McKenzie View Post
    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.

  3. #18
    Join Date
    Apr 1999
    Posts
    27,449

    Re: How to create a pointer to 'this'?

    Quote Originally Posted by nuzzle View Post
    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

  4. #19
    Join Date
    May 2009
    Posts
    2,413

    Re: How to create a pointer to 'this'?

    Quote Originally Posted by Paul McKenzie View Post
    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.

  5. #20
    Join Date
    Apr 1999
    Posts
    27,449

    Re: How to create a pointer to 'this'?

    Quote Originally Posted by nuzzle View Post
    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

  6. #21
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: How to create a pointer to 'this'?

    Quote Originally Posted by nuzzle View Post
    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.

  7. #22
    Join Date
    May 2009
    Posts
    2,413

    Re: How to create a pointer to 'this'?

    Quote Originally Posted by Arjay View Post
    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() {}

  8. #23
    Join Date
    May 2009
    Posts
    2,413

    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.

  9. #24
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: How to create a pointer to 'this'?

    Quote Originally Posted by nuzzle View Post
    I'll illustrate with a code snippet,

    void main() {}
    I was hoping for a serious example.

  10. #25
    Join Date
    May 2009
    Posts
    2,413

    Re: How to create a pointer to 'this'?

    Quote Originally Posted by Arjay View Post
    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.

  11. #26
    Join Date
    Jan 2008
    Location
    California, USA
    Posts
    822

    Re: How to create a pointer to 'this'?

    Quote Originally Posted by nuzzle View Post
    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.

  12. #27
    Join Date
    Feb 2005
    Posts
    2,160

    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.

  13. #28
    Join Date
    Jun 2008
    Posts
    592

    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

Page 2 of 2 FirstFirst 12

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
  •  





Click Here to Expand Forum to Full Width

Featured