Fully specialised templates and dllexport

2019-05-26 09:59发布

Microsoft says: “Templates cannot be used with functions declared with __declspec (dllimport) or __declspec (dllexport).” (link).

What does this mean? Can I export a function which has a fully specialized template class reference as an argument?

2条回答
姐就是有狂的资本
2楼-- · 2019-05-26 10:43

That isn't a dllexport/dllimport-specific problem, its a general issue with templates - only one compiler currently implements the means to export templates, see Comeaus template FAQ for details.

Fully specialized templates however are distinct and concrete types and basically usable with the __declspec extension, but there are limitations besides the entry you linked.

Personally i'd mainly avoid templates in the interface here and only use them internally - i don't see the what big benefits the time invested in working around the limitations give you.

查看更多
一夜七次
3楼-- · 2019-05-26 10:49

It means that you can't dllexport a function template taking a std::basic_string<T>&, but you can of course dllexport a function taking a std::string&.

See also http://msdn.microsoft.com/en-us/library/twa2aw10(VS.80).aspx

查看更多
登录 后发表回答