Y
Yi Gao
Hi All,
Seems that adding a
#include "foo.cxx"
line at the end of the header file foo.h
makes life easier since we don't have to compile the foo library and
link it into the code using it.
But before I change all my previous code, could I know if doing that
is safe?
In detail, assume we have a main program in which the foo function is
called:
---------------------------------------------------------------
Way1:
in a.cxx:
#include "foo.h"
int main()
{ foo(); return 0;}
In foo.h:
void foo();
in foo.cxx
#include "foo.h"
voif foo() { // blah blah blah }
---------------------------------------------------------------
To compile that, I need to compile the foo library first and compile
a.cxx and link them.
Because I'm lazy, so I tried the Way2:
---------------------------------------------------------------
Way2, only add an include at the end of foo.h file
a.cxx is the same
foo.cxx is the same
in foo.h:
void foo();
#include "foo.cxx"
---------------------------------------------------------------
If doing this, then I just need to g++ a.cxx at a single shot.
This seems to be convenient, but is there any potential danger in
doing this vs Way1?
Thanks!
Yi
Seems that adding a
#include "foo.cxx"
line at the end of the header file foo.h
makes life easier since we don't have to compile the foo library and
link it into the code using it.
But before I change all my previous code, could I know if doing that
is safe?
In detail, assume we have a main program in which the foo function is
called:
---------------------------------------------------------------
Way1:
in a.cxx:
#include "foo.h"
int main()
{ foo(); return 0;}
In foo.h:
void foo();
in foo.cxx
#include "foo.h"
voif foo() { // blah blah blah }
---------------------------------------------------------------
To compile that, I need to compile the foo library first and compile
a.cxx and link them.
Because I'm lazy, so I tried the Way2:
---------------------------------------------------------------
Way2, only add an include at the end of foo.h file
a.cxx is the same
foo.cxx is the same
in foo.h:
void foo();
#include "foo.cxx"
---------------------------------------------------------------
If doing this, then I just need to g++ a.cxx at a single shot.
This seems to be convenient, but is there any potential danger in
doing this vs Way1?
Thanks!
Yi