|
-
Oct 10th, 2001, 09:28 PM
#1
Thread Starter
Hyperactive Member
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.
-
Oct 10th, 2001, 09:30 PM
#2
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
-
Oct 10th, 2001, 09:51 PM
#3
Thread Starter
Hyperactive Member
Amon Ra
The Power of Learning.
-
Oct 10th, 2001, 10:14 PM
#4
Member
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.
-
Oct 10th, 2001, 10:38 PM
#5
VB Me = VC++ this
ie., use this
Is not completely the same, but good enuff.
-
Oct 11th, 2001, 07:14 AM
#6
transcendental analytic
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.
-
Oct 11th, 2001, 10:05 AM
#7
Thread Starter
Hyperactive Member
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.
-
Oct 11th, 2001, 02:20 PM
#8
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.
-
Oct 11th, 2001, 05:59 PM
#9
Thread Starter
Hyperactive Member
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.
-
Oct 12th, 2001, 08:44 AM
#10
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.
-
Oct 12th, 2001, 10:01 AM
#11
Thread Starter
Hyperactive Member
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.
-
Oct 12th, 2001, 09:18 PM
#12
PowerPoster
"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.
-
Oct 12th, 2001, 09:21 PM
#13
PowerPoster
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).
-
Oct 12th, 2001, 10:20 PM
#14
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
-
Oct 14th, 2001, 10:21 AM
#15
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|