I have the following C++/CLI snippet:
.h
#pragma unmanaged
#include <vector>
public delegate std::vector<std::wstring> XYZ(const std::wstring& filter);
.cpp
XYZ^ xyz = gcnew XYZ(&myClass::xyzFunc); // <-error C2065 + C2061
This case I get at this line two errors:
error C2065: ‘xyz’ : undeclared identifier
error C2061: syntax error : identifier ‘XYZ’
However, if I change the delegate return type from vector -> wstring (for example), it works!
public delegate std::wstring XYZ(const std::wstring& filter); // <-- w/o vector<> , works!
Has anyone any idea what is the problem?
Greatly appreciated!
Clearly this is a compiler defect, it should at least have emitted a diagnostic why it didn’t add the delegate type to the symbol table. You could submit it to connect.microsoft.com but they are not going to fix it.
A workaround is to use a typedef to declare the return value type:
I would urge you a bit to treat C++/CLI as an interop language, its major reason for being. This delegate is not usable by any other managed code. Do favor String and
List<String^>here.