我有一个包含三个实体的场景:
这些是我正在使用的文件:
INativeWindow.h
#pragma once
public interface class INativeWindow
{
void Nothing();
};
CLINativeWindow.h
#pragma once
ref class NWHolder;
public ref class CLINativeWindow : System::Windows::Forms::NativeWindow, INativeWindow
{
public:
NWHolder^ Parent;
virtual void Nothing() sealed;
void DoIt();
};
CLINativeWindow.cpp
#include "stdafx.h"
#include "CLINativeWindow.h"
void CLINativeWindow::Nothing()
{
Console::Write("None");
}
void CLINativeWindow::DoIt()
{
Parent->KeyDown(this, nullptr);
};
NWHolder.h
#pragma once
#include "INativeWindow.h"
#include "CLINativeWindow.h"
public ref class NWHolder
{
internal:
event System::Windows::Forms::KeyEventHandler^ KeyDown;
public:
virtual property INativeWindow^ OwnNativeWindow
{
INativeWindow^ __clrcall get() sealed;
void __clrcall set(INativeWindow^ value) sealed;
}
private:
CLINativeWindow^ nativeWindow_;
};
NWHolder.cpp
#include "stdafx.h"
#include "NWHolder.h"
INativeWindow^ NWHolder::OwnNativeWindow::get()
{
return nativeWindow_;
}
void NWHolder::OwnNativeWindow::set(INativeWindow^ value)
{
nativeWindow_ = dynamic_cast<CLINativeWindow^>(value);
}
在编译时,我收到此错误:
Error 1 error C3767: 'NWHolder::KeyDown::raise': candidate function(s) not accessible ..\NativeWindows\CLINativeWindow.cpp 10
有什么可以做的吗?我甚至试过了#pragma make_public(System::Windows::Forms::KeyEventHandler)
但它失败了。
答案 0 :(得分:3)
C ++ / CLI事件的'raise'内部方法始终声明为protected。在NWHolder上添加名为“FireKeyDownEvent”的方法,并为其提供您喜欢的任何可访问性。