what is the use of "&" here

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Sep 2006
Posts: 32
Reputation: linq is on a distinguished road 
Solved Threads: 0
linq linq is offline Offline
Light Poster

what is the use of "&" here

 
1
  #1
Sep 22nd, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: what is the use of "&" here

 
1
  #2
Sep 22nd, 2006
> 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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 32
Reputation: linq is on a distinguished road 
Solved Threads: 0
linq linq is offline Offline
Light Poster

Re: what is the use of "&" here

 
0
  #3
Sep 22nd, 2006
acctually no warning at all.

But which one is the optimal one here? as you recommend
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,433
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1471
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: what is the use of "&" here

 
0
  #4
Sep 22nd, 2006
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC