List of articles in this column
First, what is object-oriented
Second, C language can also achieve object-oriented
Third, the non-elegant features in C + +
Iv. solve the package and avoid the interface
V. Rational use of templates to avoid code redundancy
VI, C + + can also reflect
Vii. single-Case pattern solving the construction order puzzle of static member objects and global objects
Viii. more advanced preprocessor PHP
Viii. more advanced preprocessor PHP
C + + macros are very difficult to use in some cases, such as expanding code:
Macro (A, B, C, D)
=
Func ("A", a);
Func ("B", b);
Func ("C", c);
Func ("D", D);
Test (A);
Test (B);
Test (C);
Test (D);
This is too difficult for macro, and in order to achieve a complex macro expansion, we want to implement this function with a more advanced preprocessor.
Here we use PHP for the preprocessing of the code, using the PHP code as a C + + macro.
Of course, you can also use Python to do code generation work, but because PHP is embedded, it may be easier to handle, of course, other languages with the template is also possible.
/* main.php */"return a + b;" ?>#include <iostream>usingnamespacestd;int func(intint b) { <?php echo $return_m; ?> }int main() { cout << func(12) << endl; return0;}
We generate C + + code with the following directives:
php main.php > main.cpp
OK, the following is the same as the normal project compile, you can even write PHP commands to makefile, automated generation
Object-oriented theme for
C and C + + (8)--More advanced preprocessor PHP