Hello all. I have a idea for automatic generation of headers in a c++ program. Having to maintain headers is a very time consuming task, and I think we will all benefit from such a thing. The idea is the following:
Each time the compiler finds the pragma #pragma autoinclude("foo.hpp") it does the following: 1) searches the include path for the header foo.hpp. 2) if the header does not exist, then the compiler searches for the file 'foo.cpp' 3) if the file 'foo.cpp' is found, then the header 'foo.hpp' is generated automatically from the the .cpp file. 4) if the header exists, then the compiler compares the file dates of the header and the implementation files. If the header is older than the implementation file, then a new header is generated from the implementation file. When the compiler finds a declaration in a .cpp file that is 100% the same as a declaration in a header file, then the declaration in the implementation file is ignored, because it has been created automatically in the header by the compiler. If there is a difference, then an error is declared. Example: file main.cpp: #pragma autoinclude ("foo.hpp") int main() { Foo *foo = new Foo; foo->bar(); foos.push_back(foo); } file foo.cpp: #include <list> class Foo { public: void bar() { } }; std::list<Foo *> foos; static int data = 0; The compiler generates the following header: #ifndef FOO_HPP #define FOO_HPP #include <list> class Foo { public: void bar(); }; extern std::list<Foo *> foos; #endif //FOO_HPP If such a feature existed, it would greatly speed up application development for c++ applications.