Is it OK to use boost::shared ptr in DLL interface?

前端 未结 5 569
臣服心动
臣服心动 2021-01-04 19:21

Is it valid to develop a DLL in C++ that returns boost shared pointers and uses them as parameters?

So, is it ok to export functions like this?

1.) b         


        
5条回答
  •  日久生厌
    2021-01-04 19:57

    No it is not.

    The layout of boost::shared_ptr might not be the same on both sides of the DLL boundary. (Layout is influenced by compiler version, packing pragmas, and other compiler options, as well as the actual version of the Boost source code.)

    Only "standard layout" (a new concept in C++11, related to the old "POD = plain old data" concept) types can safely be passed between separately-built modules.

提交回复
热议问题