如何在 C++/CLI 中转发声明委托?
如何?
以下内容不起作用:
delegate MyDelegate;
ref class MyDelegate;
delegate void MyDelegate;
以下内容适用于声明:
public delegate void MyDelegate(Object ^sender, MyArgs ^args);
但是将其用作前向声明给了我
error C3756: 'MyNameSpace::MyDelegate': delegate definition conflicts with an existing symbol
How?
The following did not work:
delegate MyDelegate;
ref class MyDelegate;
delegate void MyDelegate;
The following works for declaration:
public delegate void MyDelegate(Object ^sender, MyArgs ^args);
But using it as a forward declaration gives me
error C3756: 'MyNameSpace::MyDelegate': delegate definition conflicts with an existing symbol
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这项工作是为我而做的;
stdafx.h:
cli1.cpp:
我在很大程度上保留了默认的 VS 2010 C++/CLI 项目,我希望如果您遇到前向声明的麻烦,则使用命名空间 System; 也会出现在标题中:)
也许您不想使用事件? 但结构似乎很简单。
我在考虑后添加了错误检查 (使用谓词和数组编译 C++/CLI 委托调用时出错: :FindAll())。
This work's for me;
stdafx.h:
cli1.cpp:
I left the default VS 2010 C++/CLI project alone for the most part, I would expect that if your going through the trouble of forward declarations, the using namespace System; would go in the header's also :)
Maybe you did not want to use event? But it seems to simply the structure.
I added the error check after considering (Error Compiling C++/CLI Delegate call using Predicate with Array::FindAll()).