English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

i have 3 cpp, file1.cpp, file2.cpp, file3.cpp
file1.cpp: base class
file2.cpp: derived class of file1
file3.cpp: main()

in file2.cpp, i did # include "file1.cpp", but i gt and error, LNK2005

How do i include additional cpp files?

2007-05-13 13:51:23 · 5 answers · asked by fang 4 in Computers & Internet Programming & Design

im using visual c++ 2005 express

2007-05-14 05:16:50 · update #1

5 answers

Thats not right, you have to use the header files so if you wanted to include file1.cpp into your file2.cpp and file2.cpp into file3.cpp
you have to do this:

in file2.cpp
#include "file1.h"

in file 3
#include "file2.h"

This mean you have to create file1.h and file2.h. if you just change the names of those, it still wont work.

Look up on google how to create header files in C++

2007-05-13 15:06:03 · answer #1 · answered by demaman 3 · 0 1

What are you using to compile and build? Are you using an IDE like VC++ or g++?

If you are using an IDE, just add all the .cpp and .h files to the project. You don't #include other .cpp files, you include their headers .h files. The header file contains all the declarations a .cpp might need to build.

If you use g++ just put all the files on the command line as options

> g++ -o myprog file1.cpp file2.cpp file3.cpp

2007-05-13 21:42:44 · answer #2 · answered by Anonymous · 0 1

You can't assemble source files with #include (that's for headers), you need to add all cpp (c,c++ source) files to the project (in Dev for example, you'd right click on project inside the project window, add file -- when creating a new project, you also need to remove the auto-generated main file).

Hope that helps...

2007-05-13 21:25:36 · answer #3 · answered by Walt Kolo 2 · 0 1

do not include file1.cpp rather move class definition in file1.h and include file1.h

2007-05-14 04:20:40 · answer #4 · answered by ask.earn.tk 3 · 0 0

The most proper way to #include also have #ifdef #define peppered within them.

and that custom .cpp .h files use "" not angle brackets for inclusion.

2007-05-13 21:50:08 · answer #5 · answered by Andy T 7 · 0 1

fedest.com, questions and answers