"mikelinyoho" <mi*********@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
Does the following program architecture make sense?
#include <stdio.h>
#include "test1.c"
#include "sample.cpp"
int main(void){
output();
output();
testmain();
getchar();
return 0;
}
-------------------------------------
#include"test1.c"
#include"sample.cpp"
include *.c and *.cpp at the same time?
Yikes. With this construct you force the preprocessor to include the actual
code of test1.c and sample.cpp into your current file. This will be accepted
by the compiler, although it is not what #include is actually meant for. The
idea is to have the interface in a header file and the actual implementation
in a .cpp (or for example .cxx) file. In order to have the interface
available you include it with the include statement, but you do not do this
for the actual implementation.
C++ supports different compilation units, which basically means that you can
split your program into different files where you maintain the actual
implementation. The compiler will create object files for each of these and
the linker will combine them into an executable. If you split up your
program (and this is actually good practice), you will have to use a
procedure to compile all of the files in your project separately (via a
makefile or project-file) and link them afterwards. With the inclusion of
the .c and the .cpp file you would have to compile one file only, but I
would very much recommend to stay away from this.
Best regards
Chris