what is the use of "&" here
-
look at "dc.SelectObject(&pen)" and "dc.SelectObject (&brush)",here no matter I use "&" or not it results the same. why is that? [code] void CMainWindow::OnPaint () { CPaintDC dc (this); CBrush brush (RGB (255, 0, 0)); CPen pen (PS_NULL, 0, (RGB (0, 0, 0))); dc.SelectObject(&pen); dc.SelectObject (&brush); dc.Ellipse (0, 0, 200, 100); }
-
look at "dc.SelectObject(&pen)" and "dc.SelectObject (&brush)",here no matter I use "&" or not it results the same. why is that? [code] void CMainWindow::OnPaint () { CPaintDC dc (this); CBrush brush (RGB (255, 0, 0)); CPen pen (PS_NULL, 0, (RGB (0, 0, 0))); dc.SelectObject(&pen); dc.SelectObject (&brush); dc.Ellipse (0, 0, 200, 100); }
bloodwinner wrote:
look at "dc.SelectObject(&pen)" and "dc.SelectObject (&brush)",here no matter I use "&" or not it results the same. why is that?
Because
CGdiObject
, which is whatCPen
andCBrush
are derived from, has aHGDIOBJ()
operator. Control eventually goes toCDC::SelectObject(HGDIOBJ hObject)
. When a pointer is passed instead, control goes right toCDC::SelectObject(CPen* pPen)
.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
-
bloodwinner wrote:
look at "dc.SelectObject(&pen)" and "dc.SelectObject (&brush)",here no matter I use "&" or not it results the same. why is that?
Because
CGdiObject
, which is whatCPen
andCBrush
are derived from, has aHGDIOBJ()
operator. Control eventually goes toCDC::SelectObject(HGDIOBJ hObject)
. When a pointer is passed instead, control goes right toCDC::SelectObject(CPen* pPen)
.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
do you mean both these two ways are ok? which would you prefer here?
-
do you mean both these two ways are ok? which would you prefer here?
bloodwinner wrote:
do you mean both these two ways are ok?
Sure. Otherwise, why would both exist?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb