Thread: This

  1. #1
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,490

    This

    Is it possible to assign the this pointer to a pointer variable outside the function's scope, and then use that pointer without problems?

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    That would take about 5 lines of code to test, and about 5 minutes of your time. Why don't you get some initiative?
    Last edited by 7stud; 04-06-2003 at 05:21 PM.

  3. #3
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    >>That would take about 5 lines of code

    I'd like to see that.

  4. #4
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    im not sure i totaly understand your question but maybe this will help.

    'this' is a pointer to the object. so, if you want another pointer to have the same value as 'this' then...

    Code:
    object o;
    ......
    
    object* myNewThis;
    
    myNewThis = &o;
    now 'myNewThis' has the same value as the 'this' pointer used inside the object class when refering to object 'o'

    the way you worded the question seems like you had something like this in mind...
    Code:
    object* object::getThis()
    {
        return this;
    }
    ........
    object o;
    .....
    object* myNewThis = o.getThis();
    once again myNewThis has the same value as 'this' for the object 'o' . this is the same result as the above example. and the myNewThis pointer should behave fine. it is no different than a regular pointer to an object.

    if what i just said had nothing to do with your question then just ignore me, lol. ive been writing a PHIL essay for the past 4 hours and im starting to lose sanity.

  5. #5
    The Pantless Man CheesyMoo's Avatar
    Join Date
    Jan 2003
    Posts
    262
    That was 6 lines, too bad.

    Haha, just kidding.
    If you ever need a hug, just ask.

  6. #6
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    Do parentheses count?

  7. #7
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    Originally posted by 7stud
    Do parentheses count?
    yes.

  8. #8
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    Originally posted by CheesyMoo
    That was 6 lines, too bad.

    Haha, just kidding.
    actually it was 7, but i gave two examples of the same thing which implies an average of 4.5 lines. woohoo, i win!

    actually the ' .... ' in my code would really make up a bunch more for a working test... ahhh well.

  9. #9
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,490
    I found my problem...for some variables I forgot to assign this to the other pointer...

    So I guess it's legal to do. Thanks for your time.

  10. #10
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    "woohoo, i win!"

    Congratulations! You are the "Initiative Employee of the Month".

Popular pages Recent additions subscribe to a feed