Click here to Skip to main content
15,900,725 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Not much help but... Pin
Kiran Satish10-Oct-04 9:37
Kiran Satish10-Oct-04 9:37 
GeneralRe: Not much help but... Pin
Kiran Satish23-Sep-04 6:28
Kiran Satish23-Sep-04 6:28 
GeneralRe: Not much help but... Pin
Christian Graus23-Sep-04 10:58
protectorChristian Graus23-Sep-04 10:58 
GeneralRe: Not much help but... Pin
Kiran Satish23-Sep-04 12:02
Kiran Satish23-Sep-04 12:02 
GeneralCTreeCtrl highlight design question ... Pin
Maximilien20-Sep-04 10:06
Maximilien20-Sep-04 10:06 
GeneralProblmes using std::map in a class Pin
Rickard Andersson2020-Sep-04 9:26
Rickard Andersson2020-Sep-04 9:26 
GeneralRe: Problmes using std::map in a class Pin
Navin20-Sep-04 11:06
Navin20-Sep-04 11:06 
GeneralRe: Problmes using std::map in a class Pin
Jörgen Sigvardsson20-Sep-04 13:40
Jörgen Sigvardsson20-Sep-04 13:40 
You just stumbled onto infinity, believe it or not. Smile | :)

When the C++ compiler finds a struct or a class it needs to know the size of it, so that it can allocate correct memory buffers to store the objects in. So when it finds a struct, it goes through each member variable, summing up the size of each member. That's the size the struct will get (not considering alignment issues, but that's not important in this case). Simple addition basically.

So consider this struct:
struct X {
   X x;
}
What is the size of objects of type X? It's the size of x. So, what's the size of x? Since it's of type X, it's the size of objects of type X. What is the size of objects of type X? ... and so on.

Do you see the infinite recursion here? X depends on itself, and thus its size is undefined, and is rejected by the compiler as an undefined type. A type in C++ is not complete (undefined as the compiler said) unless its size is known.

Navin suggested you could use pointers instead. How does that help you might wonder? The easy answer is that pointers on most platforms come in one size only (this is not entirely true, as old DOS programmers can testify, but don't worry about that for now). On a 32-bit compiler, pointers are typically 4 bytes large. 32 bits = 4 * 8 bits = 4 * 1 bytes. So, by using pointers instead, the compiler can determine the correct size.

--
Arigato gozaimashita!
GeneralRe: Problmes using std::map in a class Pin
Rickard Andersson2020-Sep-04 23:27
Rickard Andersson2020-Sep-04 23:27 
GeneralRe: Problmes using std::map in a class Pin
Moak21-Sep-04 1:13
Moak21-Sep-04 1:13 
Generalwinbase.h and STILL_ACTIVE Pin
ns20-Sep-04 8:40
ns20-Sep-04 8:40 
QuestionDialog window class name? Pin
0v3rloader20-Sep-04 8:22
0v3rloader20-Sep-04 8:22 
AnswerRe: Dialog window class name? Pin
mfcuser20-Sep-04 9:40
mfcuser20-Sep-04 9:40 
AnswerRe: Dialog window class name? Pin
David Crow20-Sep-04 10:28
David Crow20-Sep-04 10:28 
AnswerRe: Dialog window class name? Pin
Jörgen Sigvardsson20-Sep-04 13:27
Jörgen Sigvardsson20-Sep-04 13:27 
AnswerRe: Dialog window class name? Pin
Sujan Christo20-Sep-04 18:00
Sujan Christo20-Sep-04 18:00 
QuestionHow to programmatically show and hide Windows XP destktop icons? Pin
Steve Messer20-Sep-04 7:08
Steve Messer20-Sep-04 7:08 
GeneralC++ question Pin
Anonymous20-Sep-04 6:20
Anonymous20-Sep-04 6:20 
GeneralRe: C++ question Pin
Bob Stanneveld20-Sep-04 6:34
Bob Stanneveld20-Sep-04 6:34 
GeneralRe: C++ question - sorry Pin
Anonymous20-Sep-04 6:52
Anonymous20-Sep-04 6:52 
GeneralRe: C++ question - sorry Pin
Bob Stanneveld20-Sep-04 6:57
Bob Stanneveld20-Sep-04 6:57 
GeneralRe: C++ question - sorry Pin
Anonymous20-Sep-04 7:40
Anonymous20-Sep-04 7:40 
GeneralRe: C++ question - sorry Pin
Bob Stanneveld20-Sep-04 9:08
Bob Stanneveld20-Sep-04 9:08 
GeneralRe: C++ question - sorry Pin
David Crow20-Sep-04 10:25
David Crow20-Sep-04 10:25 
GeneralPlease explain this. Pin
V.20-Sep-04 5:29
professionalV.20-Sep-04 5:29 

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.