diff --git a/doc/modules/ROOT/examples/shared_libs/implicit_linking/main.cpp b/doc/modules/ROOT/examples/shared_libs/implicit_linking/main.cpp index c872dbe8..1f844b81 100644 --- a/doc/modules/ROOT/examples/shared_libs/implicit_linking/main.cpp +++ b/doc/modules/ROOT/examples/shared_libs/implicit_linking/main.cpp @@ -16,6 +16,7 @@ using namespace boost::openmethod::aliases; struct Tiger : Carnivore {}; BOOST_OPENMETHOD_CLASSES(Tiger, Carnivore); +BOOST_OPENMETHOD_CLASSES(Animal, Herbivore, Cow, Carnivore, Wolf); BOOST_OPENMETHOD_OVERRIDE( meet, (virtual_ptr a, virtual_ptr b), std::string) { diff --git a/doc/modules/ROOT/pages/shared_libraries.adoc b/doc/modules/ROOT/pages/shared_libraries.adoc index 716a6fd2..81ff0008 100644 --- a/doc/modules/ROOT/pages/shared_libraries.adoc +++ b/doc/modules/ROOT/pages/shared_libraries.adoc @@ -119,7 +119,8 @@ include::{shared}/implicit_linking/extensions.cpp[tag=content] ---- The program extends it. It adds a class the library has never heard of, two -overriders that specialise `meet`, and imports the state through the header: +overriders that specialise `meet`, and imports the state through the header. It +also registers the library's classes a second time - see below: [source,c++] ---- @@ -131,6 +132,18 @@ the library's `Animal, Animal` overrider, so control crosses the module boundary in the middle of a single dispatch, and `cow meets wolf` prints `do not greet, run`. +The program registers `Animal`, `Herbivore`, `Cow`, `Carnivore` and `Wolf`, +although the library has registered them already. That is the rule +cpp:use_classes[] states: a class must be registered in as many translation +units as it has type ids. On ELF and Mach-O it has one - the dynamic linker +merges the `type_info` objects, and the second registration is redundant but +harmless. Windows keeps one `type_info` per module, so the program's `Wolf` and +the library's `Wolf` are two different type ids, and the program creates its +`Wolf` with `new`. Without the second registration the program's id is unknown +to the registry, and the first dispatch on it fails with `unknown class Wolf`. +Registering in both modules is what makes the example portable, and costs +nothing where it is not needed. + ## Dynamic Linking By "dynamic linking", we mean a program loading a shared library after it has