C ++ CLI KeyDown :: raise错误错误C3767候选函数不可访问

时间:2012-07-06 14:40:20

标签: winforms events event-handling compiler-errors c++-cli

我有一个包含三个实体的场景:

  • 具有一个方法存根的接口
  • 继承自`System :: Windows :: Forms :: NativeWindow`并实现接口
  • 的类
  • 一个包装类,它具有类类型的私有成员和接口类型的公共属性。这个类还有一个`KeyDown`事件成员,它将从窗口类
  • 中调用/引发

这些是我正在使用的文件:

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)但它失败了。

1 个答案:

答案 0 :(得分:3)

C ++ / CLI事件的'raise'内部方法始终声明为protected。在NWHolder上添加名为“FireKeyDownEvent”的方法,并为其提供您喜欢的任何可访问性。