How to auto-include all headers in directory
No. You have to include them all if that's what you want to do.
No. At least, not in a way that's actually going to save typing.
Of course, you could write a script to create main.cpp for you...
If you build your code using make
, you should be able to do this.
Can I include all headers in the directory so at least I don't have to change the #include line?
Change your include line to something like #include <all_headers.h>
. Now, you can let your Makefile auto-generate all_headers.h
with a target like:
all_headers.h:
for i in `ls *.h`; do echo "#include <$i>" >>all_headers.h; done
Make sure that all_headers.h
is getting deleted when you 'make clean'.
Better yet, can I rewrite my solution so that I don't even have to touch main.cpp, without having one file with all the code for every exercise in it?
You can do this if you abstract away your class with a typedef
. In your example, change your class name from E0614
to myClass
(or something). Now, add a line to your Makefile underneath the for
loop above that says echo "typedef "$MY_TYPE" myClass;" >>all_headers.h
. When you build your program, invoke 'make' with something like make MY_TYPE=E0614
and your typedef will be automatically filled in with the class you are wanting to test.
If you're on Unix system, you can have a softlink that points to the latest excercise.
ln -s e0615.h latest.h
and name your class E instead of E0614, of course
P.S. To the best of my knowledge, you can't do #include xxx*