@@ -27,7 +27,8 @@ it is "called" only in a non-evaluated context.
2727* It defines an inline function with the same name and signature as the
2828method (with the `virtual_` decorators stripped).
2929
30- Next, let's implement the `Cat` class, in the `felines` namespace:
30+ Next, let's implement the `Cat` class, and a derived class, `Chhetah` , in the
31+ `felines` namespace:
3132
3233[source,c++]
3334----
@@ -40,10 +41,10 @@ include::{examplesdir}/headers_namespaces/cat.cpp[]
4041----
4142
4243`BOOST_OPENMETHOD_CLASSES` should be placed in an implementation file. It can
43- also go in a header file, but this wastes space, as multiple copies of the same
44- class data will be created . It doesn't matter which namespace the macro is
45- called in. It can take be used with any class name in scope, or with qualified
46- names.
44+ also go in a header file, but this wastes space, as the same registrar will be
45+ created in every translation unit that includes the header . It doesn't matter
46+ which namespace the macro is called in. It can take be used with any class name
47+ in scope, or with qualified names.
4748
4849`BOOST_OPENMETHOD_OVERRIDE` uses the guide function declared by
4950`BOOST_OPENMETHOD` to locate a method that can be called with the same arguments
@@ -63,26 +64,47 @@ struct, it defines the `next` and `has_next` members, and a static function
6364called `fn` . The block following the macro is the body of the `fn` function.
6465
6566 It follows that `BOOST_OPENMETHOD_OVERRIDE` should be placed in an
66- implementation file.
67+ implementation file. `BOOST_OPENMETHOD_INLINE_OVERRIDE` works like
68+ `BOOST_OPENMETHOD_OVERRIDE` , but it defines the `fn` function as inline, so it
69+ can be used in a header file.
6770
68- Let's implement the `Dog` class, in the `canines` namespace:
71+ The overrider for Cats can be accessed in the same translation unit, after it
72+ has been defined, using the `BOOST_OPENMETHOD_OVERRIDER` macro. It expands to
73+ the specialization of the overrider container for the overrider's signature. We
74+ call the static `fn` function to call the overrider.
6975
76+ NOTE: The Cheetah overrider calls the specific overrider for `Cat` , for
77+ illustration purpose. It is usually better to call `next` instead.
78+
79+ Let's implement the `Dog` class, in the `canines` namespace. This time we want
80+ the overrider to be accessible in other translation units. We can declare an
81+ overrider with `BOOST_OPENMETHOD_DECLARE_OVERRIDER` , without actually defining
82+ the static function `fn` just yet.
7083
7184[source,c++]
7285----
7386include::{examplesdir}/headers_namespaces/dog.hpp[]
7487----
7588
89+ Unlike function declarations, which can occur multiple times in a TU, an
90+ overrider declaration cannot. For example, this is illegal:
91+
92+ `` `c++
93+ BOOST_OPENMETHOD_DECLARE_OVERRIDER(
94+ poke, (std::ostream&, virtual_ptr<Dog>), void);
95+
96+ BOOST_OPENMETHOD_DECLARE_OVERRIDER(
97+ poke, (std::ostream&, virtual_ptr<Dog>), void);
98+ ```
99+
100+ Now we use `BOOST_OPENMETHOD_DEFINE_OVERRIDER` to define the overrider:
101+
76102[source,c++]
77103----
78104include::{examplesdir}/headers_namespaces/dog.cpp[]
79105----
80106
81- `BOOST_OPENMETHOD_INLINE_OVERRIDE` works like `BOOST_OPENMETHOD_OVERRIDE` , but
82- it can be used in a header file, because it defines the `fn` function inline.
83-
84-
85- Let's look at the main program now. It derived `Bullgod` from `Dog` and provides
107+ Let's look at the main program now. It derived `Bulldog` from `Dog` and provides
86108an overrider for the new class:
87109
88110[source,c++]
@@ -154,12 +176,12 @@ BOOST_OPENMETHOD_OVERRIDE(
154176```
155177
156178But `BOOST_OPENMETHOD_OVERRIDE` also uses the name to derive the overrider
157- container's name, using preprocessor token pasting. And the result will be an
158- invalid declaration.
179+ container's name, using preprocessor token pasting, resulting in an invalid
180+ declaration error .
159181
160- All we need to do is to make `BOOST_OPENMETHOD_OVERRIDE` "see" the guide
161- function. Its name is produced by macro `BOOST_OPENMETHOD_GUIDE(NAME)` . Thus we
162- can use a using-declaration to bring the guide function into the current scope:
182+ We need to do is to make `BOOST_OPENMETHOD_OVERRIDE` "see" the guide function.
183+ Its name is returned by macro `BOOST_OPENMETHOD_GUIDE(NAME)` . We can use a
184+ using-declaration to bring the guide function into the current scope:
163185
164186`` `c++
165187using app_specific_behavior::BOOST_OPENMETHOD_GUIDE(meet);
0 commit comments