Click here to Skip to main content
15,901,853 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: WM_USER message Pin
Alexinuk26-Nov-02 4:45
Alexinuk26-Nov-02 4:45 
GeneralRe: WM_USER message Pin
Roger Allen26-Nov-02 4:48
Roger Allen26-Nov-02 4:48 
GeneralRe: WM_USER message Pin
Roger Stewart26-Nov-02 4:53
professionalRoger Stewart26-Nov-02 4:53 
GeneralMFC and java difference: Pin
ns26-Nov-02 3:46
ns26-Nov-02 3:46 
GeneralRe: MFC and java difference: Pin
roel_26-Nov-02 4:01
roel_26-Nov-02 4:01 
GeneralRe: MFC and java difference: Pin
ns26-Nov-02 4:10
ns26-Nov-02 4:10 
GeneralRe: MFC and java difference: Pin
roel_26-Nov-02 4:21
roel_26-Nov-02 4:21 
GeneralRe: MFC and java difference: Pin
Alvaro Mendez27-Nov-02 11:15
Alvaro Mendez27-Nov-02 11:15 
I see that you're confusing some basic principles of memory allocation in C++ vs. Java. In C++ objects (such as CString) can be allocated on the stack or on the heap.

// Allocated on the stack
CString s1 = "abc";
CString s2 = "def";  
 
// Allocated on the heap
CString* ps1 = new CString("abc"); 
CString* ps2 = new CString("def"); 

When you allocate an object on the stack, the variable that you get represents the actual memory block that it takes to hold it. So s1 is the block of memory that holds "abc" and all the members of the object. And &s1 is the address of that block of memory. When you say (s1 == s2), you're comparing the blocks of memory themselves. When you say (&s1 == &s2) you're comparing the address of the blocks of memory.

When you allocate on the heap, the new operator gives you back the address of the block of bytes where the object is allocated -- basically the equivalent of &s1. When you say (ps1 == ps2), you're comparing the address of the blocks of memory. When you say (*ps1 == *ps2) you're comparing the blocks of memory themselves.

In Java, there's the String object which you can create like this:

// Always allocated on the heap
String rs1 = "abc";
String rs2 = new String("def");


Either way you do it, you always end up with the equivalent of ps1 and ps2 -- in other words, rs1 basically hold the address of the block of bytes where the actual String is allocated. In Java rs1 and rs2 are called references. In C++, ps1 and ps2 are pointers. So, like in C++, if you say (rs1 == rs2), you're comparing the address of the blocks of memory, not their content. To compare their content you can use the equals method of the String class.

I hope this shed some light on the issue.

Regards,
Alvaro




Well done is better than well said. -- Benjamin Franklin
(I actually prefer medium-well.)
GeneralAccessing CFooDoc CFooView from CFooDlg Pin
loic26-Nov-02 3:39
loic26-Nov-02 3:39 
GeneralRe: Accessing CFooDoc CFooView from CFooDlg Pin
Hernan Breinbauer26-Nov-02 3:44
Hernan Breinbauer26-Nov-02 3:44 
GeneralRe: Accessing CFooDoc CFooView from CFooDlg Pin
loic26-Nov-02 3:53
loic26-Nov-02 3:53 
GeneralRe: Accessing CFooDoc CFooView from CFooDlg Pin
Hernan Breinbauer26-Nov-02 5:12
Hernan Breinbauer26-Nov-02 5:12 
GeneralRe: Accessing CFooDoc CFooView from CFooDlg Pin
loic27-Nov-02 23:13
loic27-Nov-02 23:13 
QuestionWhy canot disable the popup menu item? Pin
Anonymous26-Nov-02 3:32
Anonymous26-Nov-02 3:32 
AnswerRe: Why canot disable the popup menu item? Pin
Roger Allen26-Nov-02 4:50
Roger Allen26-Nov-02 4:50 
GeneralInput validation Pin
Andy H26-Nov-02 3:17
Andy H26-Nov-02 3:17 
GeneralRe: Input validation Pin
roel_26-Nov-02 4:04
roel_26-Nov-02 4:04 
GeneralRe: Input validation Pin
Roger Stewart26-Nov-02 4:58
professionalRoger Stewart26-Nov-02 4:58 
GeneralRe: Input validation Pin
perlmunger26-Nov-02 7:08
perlmunger26-Nov-02 7:08 
GeneralRe: Input validation Pin
valikac26-Nov-02 8:09
valikac26-Nov-02 8:09 
GeneralRe: Input validation Pin
Mike Eriksson26-Nov-02 23:52
Mike Eriksson26-Nov-02 23:52 
GeneralCDialog::OnPaint() doesn't get called Pin
User 665826-Nov-02 3:15
User 665826-Nov-02 3:15 
GeneralRe: CDialog::OnPaint() doesn't get called Pin
Jeff Patterson26-Nov-02 3:44
Jeff Patterson26-Nov-02 3:44 
GeneralOOPS Re: CDialog::OnPaint() doesn't get called Pin
Jeff Patterson26-Nov-02 3:51
Jeff Patterson26-Nov-02 3:51 
GeneralEmbeded Object Pin
millertm26-Nov-02 2:58
millertm26-Nov-02 2:58 

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.