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
Printable View
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
I believe & is the AddressOf operator, yes.
:)
what about Me?
thanks
If you pass a variable to a function and it does not need to be modified, here's a trick that saves memory:Quote:
Originally posted by crptcblade
I believe & is the AddressOf operator, yes.
:)
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.Code:int foo(const int &i)
VB Me = VC++ this
ie., use this
Is not completely the same, but good enuff.
AddressOf in vb is only used to retrieve the address of a function. the function name addresses the function in C++Quote:
Originally posted by crptcblade
I believe & is the AddressOf operator, yes.
:)
& in C++ is used to retrieve the address of a variable, equivalent to varptr in vb.
so isn't "this" used in classes?
then if i can use it outside classes, i can use it replace "Me" right?
thanks
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:
This is a cool way to use the this-pointer.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;
There is another:
The A class requires a B pointer in it's constructor. To get one, you need the this pointer in the B constructor.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
{
}
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
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.
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 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.
"Me" is just used in vb. You need to use the handle of the window to work with its properties.Quote:
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 =)
And you always use API to do that because there is no object in C++ (like form,timer,commandbutton,etc in vb).
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
uuhhh. jim, what has this got to do with the thread? Nothing personal, just wondering...