apolukhin / Boost.DLL

Library for comfortable work with DLL and DSO
https://boost.org/libs/dll
109 stars 69 forks source link

Problem with "Factory method in plugin" example #62

Open lewandowski-a-j-gmail-com opened 1 year ago

lewandowski-a-j-gmail-com commented 1 year ago

Hi, The problem is with the tutorial, not the library itself. Your factory method in tutorial returns boost::shared_ptr. However, you import it via alias, as function returning boost::shared_ptr, which is quite confusing. I was wondering HOW this could even work in general, with all the low level stuff going on, but I checked that it doesn't really work: program crashes (in gcc and clang) as soon as address of my_plugin_api subobject differs from that of my_plugin_aggregator object. To see the problem, simply change my_plugin_aggregator to something like class my_plugin_aggregator : public S, public my_plugin_api {/*.../*}; with struct S { float f = 13.0; virtual ~S() = default; };

By constrast, if your factory method returns boost::shared_ptr (as it should I guess), everythng works just fine with new version of my_plugin_aggregator.

`