944,216 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 996
  • C RSS
Sep 22nd, 2006
1

what is the use of "&" here

Expand Post »
look at "dc.SelectObject(&pen)" and "dc.SelectObject (&brush)",here no matter I use "&" or not it results the same. why is that?
  1. void CMainWindow::OnPaint ()
  2. {
  3. CPaintDC dc (this);
  4. CBrush brush (RGB (255, 0, 0));
  5. CPen pen (PS_NULL, 0, (RGB (0, 0, 0)));
  6.  
  7. dc.SelectObject(&pen);
  8. dc.SelectObject (&brush);
  9. dc.Ellipse (0, 0, 200, 100);
  10. }
Last edited by Salem; Sep 22nd, 2006 at 5:56 pm. Reason: tagging
Similar Threads
Reputation Points: 57
Solved Threads: 0
Light Poster
linq is offline Offline
32 posts
since Sep 2006
Sep 22nd, 2006
1

Re: what is the use of "&" here

> here no matter I use "&" or not it results the same.
Well one or the other is going to produce at least a compiler warning. Choose the one which compiles cleanly.

> why is that?
Sometimes, despite the programmers' best efforts to make a mess of it, it still manages to produce the expected result.
Never confuse "expected results" and "bug free" as meaning the same thing.
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Sep 22nd, 2006
0

Re: what is the use of "&" here

acctually no warning at all.

But which one is the optimal one here? as you recommend
Reputation Points: 57
Solved Threads: 0
Light Poster
linq is offline Offline
32 posts
since Sep 2006
Sep 22nd, 2006
0

Re: what is the use of "&" here

It works because CBrush and CPen are derived from class CGdiObject, which has an operator void* that is being called when you leave out the & symbol. So the & symbol in this case is optional.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2283
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,966 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: what is the use of "pOldPen" here?
Next Thread in C Forum Timeline: help me ? Application crashing before main





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC