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

C / C++ / MFC

 
AnswerRe: Referencing a class in other in a other class Pin
Bram van Kampen2-Nov-18 14:31
Bram van Kampen2-Nov-18 14:31 
Well, Well, Well!

This question is the result of too much abstraction in education of computer scientists!
A bit of learning of how a compiler works, Things like Bits and Bytes, the underlying mechanisms, and what it cannot do would help you here. This is an insolvable problem! Ultimately, a compiler lays out code, reserves blocks of memory of a certain size, etc.

The compiler needs to know how much memory is needed for each user defined type (in C(++)) that is a union, structure or a class!
When you Declare a class, you tell the compiler to take note of the name of the class! The Linker may than be able to find that class properly defined in another file, and hence in another .obj file! The compiler cannot at that stage know anything about the size of the object, so, all you can use is either a pointer of an object of that type, or, a reference to it! A Reference to an object is very similar to a pointer, it is a compiler guaranteed pointer, that cannot be null, and always points at an object of the type!

In Your code class 'c' needs to be defined in the file before class a in which it is used! Otherwise your compiler cannot calculate the size of class a!

Best of luck learning more,

There may be rules around this conundrum in synthetic languages such as C#,Java etc. I would know nothing of these! There are no such shortcuts in C or CPP!

I encourage anyone to take up C or CPP! It are the base languages on which all others are built! A knowledge of Machine Code, and how it translates in ASM, would also help you
Bram van Kampen

QuestionPrivate test case failed Pin
Member 1403429426-Oct-18 9:35
Member 1403429426-Oct-18 9:35 
SuggestionRe: Private test case failed Pin
Richard MacCutchan26-Oct-18 22:41
mveRichard MacCutchan26-Oct-18 22:41 
QuestionRe: Private test case failed Pin
David Crow29-Oct-18 7:11
David Crow29-Oct-18 7:11 
QuestionCatch javascript event in CHtmlView Pin
_Flaviu23-Oct-18 23:37
_Flaviu23-Oct-18 23:37 
AnswerMessage Closed Pin
24-Oct-18 0:48
_Flaviu24-Oct-18 0:48 
GeneralRe: Catch javascript event in CHtmlView Pin
_Flaviu26-Oct-18 1:14
_Flaviu26-Oct-18 1:14 
AnswerRe: Catch javascript event in CHtmlView Pin
Afzaal Ahmad Zeeshan24-Oct-18 0:51
professionalAfzaal Ahmad Zeeshan24-Oct-18 0:51 
Questiondouble signed comparison in C++ Pin
kamal197723-Oct-18 16:42
kamal197723-Oct-18 16:42 
AnswerRe: double signed comparison in C++ Pin
CPallini23-Oct-18 20:47
mveCPallini23-Oct-18 20:47 
AnswerRe: double signed comparison in C++ Pin
Victor Nijegorodov23-Oct-18 21:04
Victor Nijegorodov23-Oct-18 21:04 
Questionclistctrl class Pin
Jim Overby23-Oct-18 8:01
Jim Overby23-Oct-18 8:01 
AnswerRe: clistctrl class Pin
Victor Nijegorodov23-Oct-18 8:11
Victor Nijegorodov23-Oct-18 8:11 
AnswerRe: clistctrl class Pin
Joe Woodbury23-Oct-18 8:29
professionalJoe Woodbury23-Oct-18 8:29 
SuggestionRe: clistctrl class Pin
David Crow23-Oct-18 9:34
David Crow23-Oct-18 9:34 
Questionhelp Pin
sabrina life19-Oct-18 7:54
sabrina life19-Oct-18 7:54 
AnswerRe: help Pin
OriginalGriff19-Oct-18 8:00
mveOriginalGriff19-Oct-18 8:00 
GeneralRe: ? Pin
sabrina life19-Oct-18 8:21
sabrina life19-Oct-18 8:21 
RantRe: ? Pin
David Crow19-Oct-18 10:04
David Crow19-Oct-18 10:04 
GeneralRe: ? Pin
sabrina life19-Oct-18 10:43
sabrina life19-Oct-18 10:43 
GeneralRe: ? Pin
OriginalGriff19-Oct-18 19:53
mveOriginalGriff19-Oct-18 19:53 
GeneralRe: ? Pin
sabrina life20-Oct-18 8:53
sabrina life20-Oct-18 8:53 
GeneralRe: ? Pin
OriginalGriff20-Oct-18 22:12
mveOriginalGriff20-Oct-18 22:12 
AnswerRe: help Pin
CPallini20-Oct-18 9:44
mveCPallini20-Oct-18 9:44 
GeneralRe: help Pin
sabrina life20-Oct-18 9:55
sabrina life20-Oct-18 9:55 

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.