gcnew KeyEventHandler编译问题(VC++)
我的托管 C++ 代码无法编译并显示错误消息
.\Window.cpp(11) : error C2440: 'initializing' : cannot convert from 'System::Windows::Forms::Form ^' to 'Enviroment::Window ^'
No user-defined-conversion operator available, or
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
.\Window.cpp(11) : error C3754: delegate constructor: member function 'Enviroment::Window::_keydown' cannot be called on an instance of type 'System::Windows::Forms::Form ^'
Error 1 error C2440: 'initializing' : cannot convert from 'System::Windows::Forms::Form ^' to 'Enviroment::Window ^' c:\Users\Thomas\Documents\Visual Studio 2008\Projects\Project_X\Project_X\Window.cpp 11
Error 2 error C3754: delegate constructor: member function 'Enviroment::Window::_keydown' cannot be called on an instance of type 'System::Windows::Forms::Form ^' c:\Users\Thomas\Documents\Visual Studio 2008\Projects\Project_X\Project_X\Window.cpp 11
In window.h
ref class Window
{
public:
Window();
void _keydown(System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e);
}
In window.cpp
Window::Window()
{
Form^ form = gcnew Form();
form->KeyDown+= gcnew KeyEventHandler(form, &Window::_keydown);
}
及更高版本
void Window::_keydown(System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e)
{
//stuff
}
帮助!
My managed c++ code fails to compile with the error message
.\Window.cpp(11) : error C2440: 'initializing' : cannot convert from 'System::Windows::Forms::Form ^' to 'Enviroment::Window ^'
No user-defined-conversion operator available, or
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
.\Window.cpp(11) : error C3754: delegate constructor: member function 'Enviroment::Window::_keydown' cannot be called on an instance of type 'System::Windows::Forms::Form ^'
Error 1 error C2440: 'initializing' : cannot convert from 'System::Windows::Forms::Form ^' to 'Enviroment::Window ^' c:\Users\Thomas\Documents\Visual Studio 2008\Projects\Project_X\Project_X\Window.cpp 11
Error 2 error C3754: delegate constructor: member function 'Enviroment::Window::_keydown' cannot be called on an instance of type 'System::Windows::Forms::Form ^' c:\Users\Thomas\Documents\Visual Studio 2008\Projects\Project_X\Project_X\Window.cpp 11
In window.h
ref class Window
{
public:
Window();
void _keydown(System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e);
}
In window.cpp
Window::Window()
{
Form^ form = gcnew Form();
form->KeyDown+= gcnew KeyEventHandler(form, &Window::_keydown);
}
and later
void Window::_keydown(System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e)
{
//stuff
}
Help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想你的意思是:
在C++中,类函数指针由两部分组成,实际指针(这部分你猜对了)和一个指向要传递给函数的“this”的指针,它的类型是持有该函数的类。这是您的
Window
,而不是Microsoft 的Form
。I think you mean to say:
In C++, a class function pointer is comprised of 2 things, the actual pointer (this part you got right) and a pointer to "this" to be passed to the function, which is of the type of the class holding the function. This is your
Window
, not Microsoft'sForm
.