My requirement is to get an item from a collection using extern "c" function. The method will be as below
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);
}
While compiling im getting an error as below
error C2988: unrecognizable template declaration/definition
The use of this extern
method is to get object data using pinvoke
from c#
No, that's not possible. The standard prohibits templates and their specialisations from having C linkage. Qutoing C++17 (N4659) [temp] 17/4:
... A template, a template explicit specialization (17.7.3), and a class template partial specialization shall not have C linkage. ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With