Thread: "this"

  1. #1
    Registered User stautze's Avatar
    Join Date
    Apr 2002


    Are there any uses for "this" besides cascading?
    'During my service in the United States Congress, I took the initiative in creating the Internet.' - Al Gore, March 9, 1999: On CNN's Late Edition

  2. #2
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    there are lots of uses for lots of different pointers. "this" is used so that you can internally figure out what your own pointer is. In COM you have a function called QueryInterface where there is a cast of the this pointer. looks something like this

    ptrtoreturn = (void*)(InterfaceName*)this;
    this is not exactly how they do it. They actually use static_cast but you get the idea. It's to get a pointer to a specific base class inside a void *. (in case you didn't know, base class pointers are actually a different address than the actual address)
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  3. #3
    Banal internet user
    Join Date
    Aug 2002
    sure! As long as you understand what this is, you'll use it for all sorts of stuff
    if (!this->Head) {...}
    might be used in a linked list, for example.

  4. #4
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    or another example: if a member function returns a reference or pointer to its own object.

    return *this;
    return this;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. another way for "this" pointer
    By dukebdx12 in forum C++ Programming
    Replies: 12
    Last Post: 06-23-2008, 10:52 PM
  2. Passing "this" as function parameter
    By pgavigan in forum C++ Programming
    Replies: 15
    Last Post: 07-13-2007, 10:06 AM
  3. quick question concerning "this"
    By HIM in forum C++ Programming
    Replies: 4
    Last Post: 11-04-2006, 07:17 PM
  4. the "this" pointer
    By faze in forum C++ Programming
    Replies: 7
    Last Post: 06-24-2005, 01:20 AM
  5. Replies: 2
    Last Post: 10-13-2001, 10:22 PM