C and C ++ object-oriented topics (8) -- More advanced pre-processor PHP

Source: Internet
Author: User
: 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

Related Article

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.