Object-oriented topics C and C + + (8)--More advanced preprocessor PHP

Source: Internet
Author: User
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 
   
    usingnamespacestd;int func(intint b) {    
  
    }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

The above describes the C and C + + object-oriented theme (8)-More advanced preprocessor PHP, including aspects of the content, want to be interested in PHP tutorial friends helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.