1.4. Embedding C++

We have seen that we can use binding definitions to embed C++ constants, expressions, and procedures into Felix code, and we can use the header statement to embed header text in the header (.hpp) file generated by Felix.

You can also use the body statement to embed C++ definitons in the body file Felix generates. Header text is concatenated and emitted in the header file after Felix standard definitions but before any bindings, and so is often used to embed include directives.

Body code is also collected and emitted at the top of the body (.cpp) file.

It is also possible to use the code statement to embed statements directly in procedures. This is much the same as the body statement, except that it is an executable Felix statement, and is emitted in the place it is written. For example:

Start C++ section to tut/examples/tut_bind132.flx[1 /1 ]
     1: include "std";
     2: header "#include<stdio.h>";
     3: print 1; endl;
     4: code 'printf("%d\\n",2);';
     5: print 3; endl;
     6: 
     7: 
End C++ section to tut/examples/tut_bind132.flx[1]