Click here to Skip to main content
15,910,303 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Drawing line conneting two dialogs Pin
Crercio O. Silva26-Nov-02 13:03
Crercio O. Silva26-Nov-02 13:03 
GeneralRe: Drawing line conneting two dialogs Pin
Maximilien26-Nov-02 15:20
Maximilien26-Nov-02 15:20 
GeneralRe: Drawing line conneting two dialogs Pin
Crercio O. Silva27-Nov-02 1:45
Crercio O. Silva27-Nov-02 1:45 
GeneralThreads Pin
Ruca26-Nov-02 5:59
Ruca26-Nov-02 5:59 
GeneralRe: Threads Pin
Roger Stewart26-Nov-02 6:23
professionalRoger Stewart26-Nov-02 6:23 
GeneralRe: Threads Pin
Ruca27-Nov-02 0:28
Ruca27-Nov-02 0:28 
GeneralTreeView Pin
act_x26-Nov-02 5:24
act_x26-Nov-02 5:24 
GeneralRe: TreeView Pin
dima_t26-Nov-02 18:06
dima_t26-Nov-02 18:06 
GeneralCompiler Pin
Rage26-Nov-02 5:05
professionalRage26-Nov-02 5:05 
GeneralRe: Compiler Pin
berndg26-Nov-02 5:25
berndg26-Nov-02 5:25 
GeneralRe: Compiler Pin
Rage26-Nov-02 21:05
professionalRage26-Nov-02 21:05 
GeneralWM_USER message Pin
roel_26-Nov-02 3:58
roel_26-Nov-02 3:58 
GeneralRe: WM_USER message Pin
Alois Kraus26-Nov-02 4:07
Alois Kraus26-Nov-02 4:07 
GeneralRe: WM_USER message Pin
jhwurmbach26-Nov-02 4:07
jhwurmbach26-Nov-02 4:07 
GeneralRe: WM_USER message Pin
roel_26-Nov-02 4:16
roel_26-Nov-02 4:16 
GeneralRe: WM_USER message Pin
jhwurmbach26-Nov-02 4:31
jhwurmbach26-Nov-02 4:31 
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 

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.