C ++ / CLI函数调用缺少参数列表;用于创建指向成员的指针

时间:2015-10-02 12:18:54

标签: .net visual-studio delegates c++-cli

我正在使用C ++ / CLI。 我需要传递void作为函数参数。函数参数是委托空白

我收到以下错误 错误C3867:' ChartTestApplication :: UIMain :: ChartCursorSelected':函数调用缺少参数列表;使用'& ChartTestApplication :: UIMain :: ChartCursorSelected'创建指向成员的指针

这是我定义函数的类

namespace charting 
{

public delegate void CursorPositionChanged(double x, double y);

public ref class ChartTest sealed abstract
{
static void MyFunc(Chart ^sender, CursorPositionChanged ^selectionChanged, CursorPositionChanged ^cursorMoved)
{
   // Some code here
}

}

}

这是我要调用MyFunc函数的另一个类

void UIMain::ChartCursorSelected(double x, double y)
    {
        txtChartSelect->Text = x.ToString("F4") + ", " + y.ToString("F4");
    }

    void UIMain::ChartCursorMoved(double x, double y)
    {
        txtChartValue->Text = x.ToString("F4") + ", " + y.ToString("F4");
    }

    System::Void UIMain::UIMain_Shown(System::Object^  sender, System::EventArgs^  e)
    {
        ChartTest ::MyFunc(this->mainChart, this->ChartCursorSelected, this->ChartCursorMoved);
    }

请帮忙。

1 个答案:

答案 0 :(得分:1)

这是一个代码示例。正如Hans Passant建议的那样,您可能希望在C ++ / CLI中阅读有关委托的this article

namespace charting 
{
    public delegate void CursorPositionChanged(double x, double y);

    public ref class ChartTest sealed abstract
    {
    public:
        static void MyFunc(ref class Chart ^sender, CursorPositionChanged^, CursorPositionChanged^) { }
    };

    public ref class Chart { };

    public ref class UIMain
    {
    public:
        UIMain()
            : mainChart(gcnew Chart) { }

        void ChartCursorSelected(double x, double y) { }

        void ChartCursorMoved(double x, double y) { }

        System::Void UIMain_Shown(System::Object^ sender, System::EventArgs^ e)
        {
            ChartTest::MyFunc(
                this->mainChart,
                gcnew CursorPositionChanged(this, &UIMain::ChartCursorSelected),
                gcnew CursorPositionChanged(this, &UIMain::ChartCursorMoved)
                );
        }

        Chart^ mainChart;
    };
}