Click here to Skip to main content
15,885,216 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: error C2801: 'operator =' must be a member Pin
Stephen Hewitt26-Feb-06 19:51
Stephen Hewitt26-Feb-06 19:51 
Jokesome games Pin
FARGORE26-Feb-06 3:04
FARGORE26-Feb-06 3:04 
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 
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 
CClient* pDC(this);
CPen *penRed = new CPen();

penRed->Create(PS_SOLID,1,RGB(255,0,0)); // Create a solid red pen

CPen *penOld = dc->SelectObject(penRed); // Select the red pen and store the old pen in // penOld, but why use the address of it?

//dc.DrawText(300,400,penRed,"Hello World"); // Print Hello World

dc.SelectObject(penOld) //Select the old object using the pointer
I've marked up the code you posted. Notice the bold areas.

1. The new operator returns the address of an object allocated on the heap. The value on the left side of the assignment therefore has to be a pointer variable.

2. If you refer to a member of an object through a pointer, you have to use the -> operator, as in penRed->Create.

3. The SelectObject function in the CDC class takes a pointer to a CGdiObject.

4. The CDC class doesn't have a DrawText member that takes a pen argument.



Software Zen: delete this;
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 

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.