我的要求是使用extern"c"函数从集合中获取项目.方法如下
template<class _Ty,
class _Alloc = allocator<_Ty> >
extern "C" __declspec(dllexport) _Ty* __cdecl GetItem(std::vector<_Alloc>* itr, int index)
{
if (itr->size() < index)
return NULL;
return &itr->at(index);
}
Run Code Online (Sandbox Code Playgroud)
编译时遇到如下错误
error C2988: unrecognizable template declaration/definition
Run Code Online (Sandbox Code Playgroud)
使用此extern方法是使用pinvokefrom 获取对象数据c#
不,那是不可能的.该标准禁止模板及其专业化与C链接.Qutoing C++ 17(N4659)[temp] 17/4:
...模板,模板显式特化(17.7.3)和类模板部分特化不应具有C链接....