@@ -37,11 +37,10 @@ inline auto postfix(virtual_ptr<const Node> node, std::ostream& os) -> void {
3737Before we can call the method, we need to define overriders. For that we use the
3838xref:BOOST_OPENMETHOD_OVERRIDE.adoc[BOOST_OPENMETHOD_OVERRIDE] macro:
3939
40- ```c++
41- BOOST_OPENMETHOD_OVERRIDE(postfix, (virtual_ptr<const Variable> var, std::ostream& os), void) {
42- os << var->v;
43- }
44- ```
40+ [source,cpp]
41+ ----
42+ include::{examplesdir}/ast.cpp[tag=variable_overrider]
43+ ----
4544
4645The overrider must have virtual parameters in the same positions as in the
4746method. The classes in the method's virtual parameters must be accessible,
@@ -53,32 +52,31 @@ The non-virtual parameters must have exactly the same types as in the method.
5352
5453Let's look at another overrider:
5554
56- ```c++
57- BOOST_OPENMETHOD_OVERRIDE(postfix, (virtual_ptr<const Plus> plus, std::ostream& os), void) {
58- postfix(plus->left, os);
59- os << ' ';
60- postfix(plus->right, os);
61- }
62- ```
55+ [source,cpp]
56+ ----
57+ include::{examplesdir}/ast.cpp[tag=plus_overrider]
58+ ----
6359
6460This one calls `postfix` recursively to print the left and right
6561sub-expressions. Note that we call the method just like an ordinary function.
6662
6763`postfix` expects a `virtual_ptr<const Node>`, and we are passing it a _plain_
6864_reference_ to a `Plus` object. This works because `virtual_ptr` has conversion
6965constructors from plain references or pointers to an object, or from other
70- `virtual_ptr` to compatible classes.
66+ `virtual_ptr`{empty}s to compatible classes.
7167
7268There are two more things we need to do.
7369
7470OpenMethod is a library, not a compiler. It needs to be made aware of all the
7571classes that may be used as virtual parameters, and in method calls, and their
76- inheritance relationships. We do this using the
72+ inheritance relationships. We do this with the
7773xref:BOOST_OPENMETHOD_CLASSES.adoc[BOOST_OPENMETHOD_CLASSES] macro:
7874
79- ```c++
80- BOOST_OPENMETHOD_CLASSES(Node, Variable, Plus, Times);
81- ```
75+
76+ [source,cpp]
77+ ----
78+ include::{examplesdir}/ast.cpp[tag=class_registration]
79+ ----
8280
8381Classes can be registered multiple times, in any order, and incrementally. Every
8482direct base of a class must appear together with it in at least one call to
0 commit comments