3 files = 1 program HELP!

F

firedhippy

Im very n00b to programming and im working on this project..... and
I've got 3 different files....a header file ('file.h'), an
Implementation file ('file.cpp') and a driver file ('driver.cpp'). In
both the file.cpp and driver.cpp files..i put #include "file.h" ...but
im pretty sure thats wrong...i mean how does the driver file know how
to include my "file.cpp" implementaion file?? HELP THIS plz
tx...
 
J

John Harrison

Im very n00b to programming and im working on this project..... and
I've got 3 different files....a header file ('file.h'), an
Implementation file ('file.cpp') and a driver file ('driver.cpp'). In
both the file.cpp and driver.cpp files..i put #include "file.h" ...but
im pretty sure thats wrong...

No it's right.

i mean how does the driver file know how
to include my "file.cpp" implementaion file?? HELP THIS plz
tx...

It doesn't. This is called seperate compilation. Each cpp file is
compiled seperately. Then a final stage called linking brings the two
files together.

How exactly is it going wrong for you?

john
 
F

firedhippy

Hi john,
Tx for the responce...
Well I wrote the implementation file which ONLY contains the fully
coded functions that are contained within the classes described in the
header file 'file.h'. Then the driver file uses what is contained in
both the header file and the implementation file....my question is HOW
do i "link" (as you say) these files together so that when i compile
and run the driver file...it will know to use both the .h file and the
..cpp file (implementaiton file)....
once again the three files are: ('file.h' (header) 'file.cpp'
(implementation) 'driver.cpp'
 
M

Mark P

Hi john,
Tx for the responce...
Well I wrote the implementation file which ONLY contains the fully
coded functions that are contained within the classes described in the
header file 'file.h'. Then the driver file uses what is contained in
both the header file and the implementation file....my question is HOW
do i "link" (as you say) these files together so that when i compile
and run the driver file...it will know to use both the .h file and the
.cpp file (implementaiton file)....
once again the three files are: ('file.h' (header) 'file.cpp'
(implementation) 'driver.cpp'

This depends on your compiler / development environment. For a typical
command line compiler it usually suffices to enter the single command:
<compiler command> <all .cpp file names>. In your case, if you were
using gcc, you'd enter: gcc file.cpp driver.cpp

This will tell the compiler to first compile each .cpp file separately
and then link the resulting "object files" into a single executable
(often named a.out by default).
 
F

firedhippy

I'm using Microsoft Visual C++ V. 6.0 .... I have the three files in
the same directory and I simply executed the driver file....and got
run-time errors so I'm assuming that I'm missing something.
 
R

Roberto Waltman

I'm using Microsoft Visual C++ V. 6.0 .... I have the three files in
the same directory and I simply executed the driver file....and got
run-time errors so I'm assuming that I'm missing something.

If you got "run-time" errors you compiled and linked your program
successfully, otherwise there would be no executable to run.
I believe you meant "build" time errors (meaning either compile or
link errors)

I do not have Visual Studio in front of me, so the details may be
slightly wrong, but you need to do to do the following:

(a) Create a "workspace", which is a general repository for projects,
files, resources, etc.

(b) Create a "project" and add it to the workspace in (a) You need to
chose what the project will be: A console application, a full windows
application, a library, a dynamic link library, etc.

(c) "Add files" to the project.

(d) Then "build" it.

If you still have problems you should ask in a forum / newsgroup
dedicated to Visual C++ (look at the various microsoft.public.????
newsgroups) This newsgroup is for generic C++, not for details that
are particular to Visual C++.
 
F

firedhippy

Thank you very much Roberto........that totally answered my question
and I apologize for 1) not being specific as to my question and 2) not
posting in the correct newsgroup. Thanks again
 
H

Havatcha

Thank you very much Roberto........that totally answered my question
and I apologize for 1) not being specific as to my question and 2) not
posting in the correct newsgroup. Thanks again

What a polite young man.
 
S

Sherm Pendley

He is isn't he?

Yes, definitely. It's a shame that such manners are so rare as to be worthy of
comment though. Courtesy should be the rule, not the exception. :-(

sherm--
 

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

Forum statistics

Threads
474,291
Messages
2,571,493
Members
48,165
Latest member
JerrodPaqu

Latest Threads

Top