本文介绍了如何在C ++ / CLI中转发声明一个委托?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何?
以下操作无效:
delegate MyDelegate;
ref class MyDelegate;
delegate void MyDelegate;
以下适用于声明:
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
推荐答案
这项工作适合我;
stdafx.h:
public delegate void Handler(bool isit);
cli1.cpp:
#include "stdafx.h"
using namespace System;
namespace MY {
namespace Namespace
{
public ref class Objeks
{
public: Objeks() {}
public: event Handler^ OnHandler;
public: void __clrcall Runner(bool checkit)
{
if(&Objeks::OnHandler != nullptr)
OnHandler(checkit);
}
};
}
}
我离开了默认的VS 2010 C ++ / CLI项目在大多数情况下,我希望如果你经历前进声明的麻烦,使用命名空间System;也会在标题的另外:)
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 (http://stackoverflow.com/questions/649633/error-compiling-c-cli-delegate-call).
这篇关于如何在C ++ / CLI中转发声明一个委托?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!