C++/CLI: make public for template type

那年仲夏 提交于 2019-12-14 02:21:49

问题


AFAIK #pragma make_public supports only native non-template types.

But, is there some other way to make template type as public?


回答1:


No. But read here for some workarounds:

  • Best workaround for compiler error C2158: make_public does not support native template types

  • http://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/b43cca63-b0bf-451e-b8fe-74e9c618b8c4/




回答2:


Templates don't have external linkage. Not in native C++, not in C++/CLI either. You solve it the same way, put them in a .h header file and #include it in any source file where you want to use the template. They are of course not available to any other managed code that isn't written in C++/CLI.

Do favor the generic keyword in C++/CLI, generics in managed code do have the equivalent of external linkage.



来源:https://stackoverflow.com/questions/12800262/c-cli-make-public-for-template-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!