C++/CLI 函数调用缺少参数列表;用于创建指向成员的指针
C++/CLI function call missing argument list; use to create a pointer to member
我正在使用 C++/CLI。
我需要将 void 作为函数参数传递。函数参数是一个委托 void
我收到以下错误
error C3867: 'ChartTestApplication::UIMain::ChartCursorSelected': 函数调用缺少参数列表;使用 '&ChartTestApplication::UIMain::ChartCursorSelected' 创建一个指向 member
的指针
这里是 class 我定义函数的地方
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
}
}
}
这是另一个 class 我想调用 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);
}
请帮忙。
这是一个代码示例。正如 Hans Passant 建议的那样,您可能需要阅读 this article 关于 C++/CLI 中的委托。
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;
};
}
我正在使用 C++/CLI。 我需要将 void 作为函数参数传递。函数参数是一个委托 void
我收到以下错误 error C3867: 'ChartTestApplication::UIMain::ChartCursorSelected': 函数调用缺少参数列表;使用 '&ChartTestApplication::UIMain::ChartCursorSelected' 创建一个指向 member
的指针这里是 class 我定义函数的地方
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
}
}
}
这是另一个 class 我想调用 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);
}
请帮忙。
这是一个代码示例。正如 Hans Passant 建议的那样,您可能需要阅读 this article 关于 C++/CLI 中的委托。
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;
};
}