Compile header-only template library into a shared library?

后端 未结 4 1465
情深已故
情深已故 2020-12-15 11:11

We are in the process of designing a new C++ library and decided to go with a template-based approach along with some specific partial template specialisations for corner ca

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-15 11:51

    Yes. What you can do is explicitly instantiate the templates in CPP files using the compiler's explicit template instantiation syntax. Here is how to use explicit instantiation in VC++: http://msdn.microsoft.com/en-us/library/by56e477(v=VS.100).aspx. G++ has a similar feature: http://gcc.gnu.org/onlinedocs/gcc/Template-Instantiation.html#Template-Instantiation.

    Note that C++11 introduced a standard syntax for explicit instantiation, described in [14.7.2] Explicit instantiation of the FDIS:

    The syntax for explicit instantiation is:

    explicit-instantiation:

    externopt template declaration

提交回复
热议问题