Click here to Skip to main content
15,890,282 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionHow does the using the address of operator work in Visual C++? Pin
Tom Moore26-Feb-06 2:08
Tom Moore26-Feb-06 2:08 
AnswerRe: How does the using the address of operator work in Visual C++? Pin
BadKarma26-Feb-06 3:15
BadKarma26-Feb-06 3:15 
Hi,

in the case u describe it is used to pass the object by address or by reference.
It will depend on the signature of the called function. If I'm not mistaken this
function GetWindowRect expects a pass by address (a pointer) because its
based on the an API call which is written in plain C where there are no references

int iValue = 3;
int* pValue = &iValue; // pointer to value
*pValue = 4;
int& rValue = &iValue; // reference to value
rValue = 5;
Here you van see that when using a pointer (pValue) you need the to dereference it
using the '*' operator;
When using the reference (rValue) you can use it like you would have used iValue;

Now this brings the following benefit, look at the following code:
struct Point{
int x;
int y;
};

void FunctionA(Point ptMouse)
{
  ptMouse.x = 100;
}

void FunctionB(Point* pMouse)
{
  pMouse->x = 100;
}

void FunctionC(Point& rMouse)
{
  rMouse.x = 100;
}
When using FunctionA the Point object will be copied onto the stack and
in the function you only use this copy. [pass by value]
When using FunctionB only the address is placed on the stack and inside the function
you can access the original object. So when changing the object inside the function is will
be changed outside the function (its the same object) [pass by address]
When using FunctionC alsoo only the address is placed on the stack and inside we are using the original object. So when changing the object inside the function is will
be changed outside the function. [pass by reference]

When passing large objects (classes with many members, or large ones) the pass by value is not so good (slow, stack space consuming). So either pass by address or pass by reference are preferred.

codito ergo sum
GeneralRe: How does the using the address of operator work in Visual C++? Pin
Tom Moore26-Feb-06 3:31
Tom Moore26-Feb-06 3:31 
GeneralRe: How does the using the address of operator work in Visual C++? Pin
PJ Arends26-Feb-06 11:13
professionalPJ Arends26-Feb-06 11:13 
AnswerRe: How does the using the address of operator work in Visual C++? Pin
Tom Moore26-Feb-06 3:17
Tom Moore26-Feb-06 3:17 
GeneralRe: How does the using the address of operator work in Visual C++? Pin
Gary R. Wheeler26-Feb-06 5:22
Gary R. Wheeler26-Feb-06 5:22 
AnswerRe: How does the using the address of operator work in Visual C++? Pin
includeh1026-Feb-06 3:19
includeh1026-Feb-06 3:19 
GeneralRe: How does the using the address of operator work in Visual C++? Pin
Tom Moore26-Feb-06 3:34
Tom Moore26-Feb-06 3:34 
AnswerRe: How does the using the address of operator work in Visual C++? Pin
Hamid_RT26-Feb-06 3:48
Hamid_RT26-Feb-06 3:48 
AnswerRe: How does the using the address of operator work in Visual C++? Pin
Tom Moore26-Feb-06 6:10
Tom Moore26-Feb-06 6:10 
AnswerRe: How does the using the address of operator work in Visual C++? Pin
PJ Arends26-Feb-06 11:08
professionalPJ Arends26-Feb-06 11:08 
AnswerRe: How does the using the address of operator work in Visual C++? Pin
David Crow27-Feb-06 3:37
David Crow27-Feb-06 3:37 
QuestionMessage Box being hidden Pin
braveheartkenya26-Feb-06 2:04
braveheartkenya26-Feb-06 2:04 
AnswerRe: Message Box being hidden Pin
includeh1026-Feb-06 3:21
includeh1026-Feb-06 3:21 
GeneralRe: Message Box being hidden Pin
braveheartkenya26-Feb-06 4:52
braveheartkenya26-Feb-06 4:52 
AnswerRe: Message Box being hidden Pin
FarPointer26-Feb-06 3:37
FarPointer26-Feb-06 3:37 
GeneralRe: Message Box being hidden Pin
braveheartkenya26-Feb-06 4:56
braveheartkenya26-Feb-06 4:56 
GeneralRe: Message Box being hidden Pin
FarPointer26-Feb-06 5:11
FarPointer26-Feb-06 5:11 
GeneralRe: Message Box being hidden Pin
Gary R. Wheeler26-Feb-06 5:31
Gary R. Wheeler26-Feb-06 5:31 
GeneralRe: Message Box being hidden Pin
braveheartkenya26-Feb-06 6:05
braveheartkenya26-Feb-06 6:05 
GeneralRe: Message Box being hidden Pin
Ryan Binns26-Feb-06 17:19
Ryan Binns26-Feb-06 17:19 
GeneralRe: Message Box being hidden Pin
braveheartkenya27-Feb-06 7:21
braveheartkenya27-Feb-06 7:21 
GeneralRe: Message Box being hidden Pin
Nibu babu thomas26-Feb-06 18:27
Nibu babu thomas26-Feb-06 18:27 
GeneralRe: Message Box being hidden Pin
braveheartkenya27-Feb-06 7:25
braveheartkenya27-Feb-06 7:25 
QuestionHow to use LB_SETCOUNT message for MFC CListBox class? Pin
oleetron26-Feb-06 2:01
oleetron26-Feb-06 2:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.