: This article mainly introduces the object-oriented topics of C and C ++ (8)-more advanced pre-processor PHP. if you are interested in the PHP Tutorial, refer to it. List of articles in this column
1. what is object-oriented?
2. the C language can also implement object-oriented
III. non-elegant features in C ++
4. solve encapsulation and avoid interfaces
5. use templates properly to avoid code redundancy
6. C ++ reflection
VII. Singleton mode solves the difficult problem of constructing sequence of static member objects and global objects
8. more advanced pre-processor PHP
8. more advanced pre-processor PHP
The macro of C ++ is very difficult to use in some cases, such as expanding the code into the following:
Macro (A, B, C, D)
=>
Func ("A", );
Func ("B", B );
Func ("C", C );
Func ("D", D );
Test ();
Test (B );
Test (C );
Test (D );
This is too difficult for Macros. in order to implement complicated macros, we hope to use a more advanced pre-processor to implement this function.
We use PHP for code preprocessing and use PHP code as a macro of C ++.
Of course, you can also use python for code generation, but because php is embedded, it may be easier to process it. of course, other languages can also be configured with templates.
/* main.php */
#include
usingnamespacestd;int func(int a, int b) {
}int main() { cout << func(1, 2) << endl; return0;}
Run the following command to generate the C ++ code:
php main.php > main.cpp
Okay, the following is the same as normal project compilation. you can even write php commands to makefile to automatically generate