File inclusion

M

mead

This is from an article:

"Given a.h and a.cpp files, a.h has been included as the first header file
in a.cpp. This will make sure that a.h does not expect a certain header
files to be included before a.h. As a.h has been included as the first file,
successful compilation of a.cpp will ensure that a.h does not expect any
other header file to be included before a.h. If this is followed for all
classes, (i.e. x.cpp always includes x.h as the first header) there will be
no dependency on header file inclusion."

Why include a.h as first included file of a.cpp?

What does it mean "As a.h has been included as the first file, successful
compilation of a.cpp will ensure that a.h does not expect any other header
file to be included before a.h"?

What does this mean by "If this is followed for all classes, (i.e. x.cpp
always includes x.h as the first header) there will be no dependency on
header file inclusion."?

Thanks!
 
V

Victor Bazarov

mead said:
This is from an article:

"Given a.h and a.cpp files, a.h has been included as the first header file
in a.cpp. This will make sure that a.h does not expect a certain header
files to be included before a.h. As a.h has been included as the first file,
successful compilation of a.cpp will ensure that a.h does not expect any
other header file to be included before a.h. If this is followed for all
classes, (i.e. x.cpp always includes x.h as the first header) there will be
no dependency on header file inclusion."

Why include a.h as first included file of a.cpp?

Didn't you just quote the answer or do you have trouble understanding
what you quoted? Read again from "As a.h has been included ...".
What does it mean "As a.h has been included as the first file, successful
compilation of a.cpp will ensure that a.h does not expect any other header
file to be included before a.h"?

Uh... If a.h depended on some other header to be included before it
in a.cpp, then a.cpp wouldn't compile. That's the reverse assertion.
I am not sure it will help, but sometimes it does.
What does this mean by "If this is followed for all classes, (i.e. x.cpp
always includes x.h as the first header) there will be no dependency on
header file inclusion."?

Just do the same thing for all your source files. Be consistent. If
you make it compile in the case of a.cpp and a.h, why not use the same
rule for the rest of the code, eh?

Honestly, I don't know what else to tell you. Try reading the article
several more times, and slowly.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top