Results 1 to 15 of 15

Thread: quick question

  1. #1

    Thread Starter
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500

    Unhappy quick question

    probably a stupid one:
    if in VB code i encounter AddressOf, what would i replace it with in C++? just omit it? or use & ?
    thanks
    Amon Ra
    The Power of Learning.

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    I believe & is the AddressOf operator, yes.

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3

    Thread Starter
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500
    what about Me?
    thanks
    Amon Ra
    The Power of Learning.

  4. #4
    Originally posted by crptcblade
    I believe & is the AddressOf operator, yes.

    If you pass a variable to a function and it does not need to be modified, here's a trick that saves memory:

    Code:
    int foo(const int &i)
    You reference i just as normal, but since you don't need to modify it you pass a constant reference pointer instead of a whole new copy of the object/variable.

  5. #5
    jim mcnamara
    Guest
    VB Me = VC++ this

    ie., use this

    Is not completely the same, but good enuff.

  6. #6
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Originally posted by crptcblade
    I believe & is the AddressOf operator, yes.

    AddressOf in vb is only used to retrieve the address of a function. the function name addresses the function in C++

    & in C++ is used to retrieve the address of a variable, equivalent to varptr in vb.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  7. #7

    Thread Starter
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500
    so isn't "this" used in classes?
    then if i can use it outside classes, i can use it replace "Me" right?
    thanks
    Amon Ra
    The Power of Learning.

  8. #8
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    this is a POINTER, and it is used to pass the class object you are in as parameter or return value.
    For example, the MFC CRect has a function named UpperLeft() that returns a changable reference to a CPoint that represents the upper left point of the rectangle:
    Code:
    // CRect is derived from windows RECT, so it has left, top, right and bottom as members, in this order.
    // CPoint is derived from windows POINT, so it has x and y as members, in this order.
    
    // return a CPoint object through which the upper left edge of the rect can be changed
    inline CPoint & CRect::UpperLeft()
    {
        return *((CPoint*)(this));
    }
    
    // for the lower right point:
    inline CPoint & CRect::LowerRight()
    {
        return *(((CPoint*)this)+1);
    }
    
    RECT:
    LONG left, top, right, bottom;
    
    POINT:
    LONG x, y;
    This is a cool way to use the this-pointer.

    There is another:
    Code:
    class B;
    
    class A
    {
    public:
      A(B* b);
      B* parent;
    }
    
    class B
    {
    public:
      B();
      A embedded;
    }
    
    A::A(B* b)
    {
      parent = b;
    }
    
    B::B()
     : embedded(this)  // constructor list: the clean way to construct an embedded object
    {
    }
    The A class requires a B pointer in it's constructor. To get one, you need the this pointer in the B constructor.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  9. #9

    Thread Starter
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500
    okok, but what if i use "this" outside of a class? ok, i am trying to understand the ssubtimer from vbaccelerator, but i cant figure out what the me has to do when calling lets say AttachMessage..

    Code:
    AttachMessage Me, Me.hwnd, WM_SIZE
    Amon Ra
    The Power of Learning.

  10. #10
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    I don't know about Me in VB (what it does exactly).
    If you use "this" outside a class, you'll get this error:
    error C2673: '(function name)': global functions don't have a this-pointer
    As always, this is a translation from german...

    If you use the Me in a module attached to a form, al functions probably are member functions of the form class. This could be why Me works "outside" classes.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  11. #11

    Thread Starter
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500
    ok, so might the Me some sort of a pointer(i know there aren't any in VB) to the window class or something? i really need to find an equivalent..
    thanks =)
    Amon Ra
    The Power of Learning.

  12. #12
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    "Me" is no way related to "this" in a class.
    VB has just made this object to simplify the code a bit. So, for example, you don't need to write the name of the form. You can just write "Me" instead.
    Baaaaaaaaah

  13. #13
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    Originally posted by Amon Ra
    ok, so might the Me some sort of a pointer(i know there aren't any in VB) to the window class or something? i really need to find an equivalent..
    thanks =)
    "Me" is just used in vb. You need to use the handle of the window to work with its properties.
    And you always use API to do that because there is no object in C++ (like form,timer,commandbutton,etc in vb).
    Baaaaaaaaah

  14. #14
    jim mcnamara
    Guest
    anything in C that references the firaty element of a vector is in itself a pointer

    Code:
    char *t;
    char tmp[80];
      t = tmp;             << is legal

  15. #15
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    uuhhh. jim, what has this got to do with the thread? Nothing personal, just wondering...
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

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