环境
Visual Studio 2013和C ++ / CLI。
(ho / e)rror
我遇到了IntelliSense在符合编译器的行上出错的情况。 因此是假阳性。
错误如下:
IntelliSense:函数“<完全限定方法名称>”不能使用给定的参数列表调用 参数类型是: <期望参数类型> 对象类型是: <对象类型>
发生了什么
我做了一个UserControl。 在那里,我用相对代表声明了一个自定义事件。 我创建了一个表单。 在表单构造函数中,我分配了一个用户控件实例,并尝试将一个表单方法附加到控件自定义事件。
编译器说一切都好。 IntelliSense告诉我事件附件不匹配类型。
如何重现
我深入研究了这个问题并创建了一个重要的上下文来重现问题:
创建一个包含两个项目的解决方案: FavaTest (作为ClassLibrary)和FavaForm (作为控制台应用程序......或其他)。 在FavaTest创建一个名为FavaTest的UserControl,并将以下内容粘贴到FavaClass.h 。 #pragma once using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; namespace FavaTest { public ref class FavaClass : public System::Windows::Forms::UserControl { public: FavaClass(void) { InitializeComponent(); } // -- here defines very simple event -- delegate void FavaDelegate(); event FavaDelegate^ FavaEvent; protected: ~FavaClass() { if (components) { delete components; } } private: System::ComponentModel::Container ^components; #pragma region Windows Form Designer generated code void InitializeComponent(void) { this->SuspendLayout(); // // FavaClass // this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; this->Name = L"FavaClass"; this->Size = System::Drawing::Size(249, 147); this->ResumeLayout(false); } #pragma endregion }; } 在项目FavaForm创建一个名为FavaForm的Form,并将以下内容粘贴到LaForm.h namespace FavaForm { using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; public ref class LaForm : public System::Windows::Forms::Form { public: LaForm(void) { InitializeComponent(); // here simply allocs a FavaClass object and try to attach to FavaEvent event FavaTest::FavaClass ^item = gcnew FavaTest::FavaClass(); item->FavaEvent += gcnew FavaTest::FavaClass::FavaDelegate(this, &LaForm::onfava); } void onfava(){} protected: ~LaForm() { if (components) { delete components; } } private: System::ComponentModel::Container ^components; #pragma region Windows Form Designer generated code void InitializeComponent(void) { this->SuspendLayout(); // // LaForm // this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; this->ClientSize = System::Drawing::Size(368, 261); this->Name = L"LaForm"; this->Text = L"LaForm"; this->ResumeLayout(false); } #pragma endregion }; } 构建FavaTest 在FavaForm项目中, common properties添加对FavaTest的新引用,以便将其生成的dll用作依赖项 构建解决方案现在,虽然编译器预示一切都很好,但您应该看到IntelliSense在事件附件行上抱怨某事,并带有以下错误消息:
IntelliSense:函数“FavaTest :: FavaClass :: FavaEvent :: add”无法使用给定的参数列表调用 参数类型是: (FavaTest :: FavaClass :: FavaDelegate ^) 对象类型是:FavaTest :: FavaClass ^
准备运行包
我将所有这些打包在一个side-test-standalone-solution zip文件中,以便解压缩和运行,但不幸的是(恕我直言也有疑问)我不能在这里发布它的SE指南,所以这取决于你做根据上面的调试上下文。
这个问题
我也可能遗漏了一些东西,但之前我曾多次使用过这个算法并且它完美地运行了,现在我在两台不同的机器上遇到了这个问题(VS2013和VS2015)。 这个错误也适用于你吗? 智能感知有什么问题? 这是一个简单的场景,我无法想象我是唯一一个体验它的人。 我发现互联网上没有任何线索。
Environment
Visual Studio 2013 and C++/CLI.
The (ho/e)rror
I faced a situation of IntelliSense giving error on a compiler compliant row. Thus a false positive.
The error is the following:
IntelliSense: function "< full qualified method name >" cannot be called with the given argument list argument types are: < expected argument type > object type is: < object type >
What happened
I made a UserControl. There I declared a custom event with relative delegate. I created a form. In form constructor I alloc a my user control instance and try to attach a form method to the control custom event.
Compiler says everything is ok. IntelliSense tells me that event attachment mismatches types.
How to reproduce
I digged in the problem and created an essential context that should reproduce the problem:
Create a solution with two projects: FavaTest (as ClassLibrary) and FavaForm (as Console application...or whatever). In FavaTest create a UserControl whose name is FavaClass and paste the following in FavaClass.h. #pragma once using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; namespace FavaTest { public ref class FavaClass : public System::Windows::Forms::UserControl { public: FavaClass(void) { InitializeComponent(); } // -- here defines very simple event -- delegate void FavaDelegate(); event FavaDelegate^ FavaEvent; protected: ~FavaClass() { if (components) { delete components; } } private: System::ComponentModel::Container ^components; #pragma region Windows Form Designer generated code void InitializeComponent(void) { this->SuspendLayout(); // // FavaClass // this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; this->Name = L"FavaClass"; this->Size = System::Drawing::Size(249, 147); this->ResumeLayout(false); } #pragma endregion }; } In project FavaForm create a Form whose name is LaForm and paste the following in LaForm.h namespace FavaForm { using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; public ref class LaForm : public System::Windows::Forms::Form { public: LaForm(void) { InitializeComponent(); // here simply allocs a FavaClass object and try to attach to FavaEvent event FavaTest::FavaClass ^item = gcnew FavaTest::FavaClass(); item->FavaEvent += gcnew FavaTest::FavaClass::FavaDelegate(this, &LaForm::onfava); } void onfava(){} protected: ~LaForm() { if (components) { delete components; } } private: System::ComponentModel::Container ^components; #pragma region Windows Form Designer generated code void InitializeComponent(void) { this->SuspendLayout(); // // LaForm // this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; this->ClientSize = System::Drawing::Size(368, 261); this->Name = L"LaForm"; this->Text = L"LaForm"; this->ResumeLayout(false); } #pragma endregion }; } Build FavaTest In FavaForm project common properties add a new reference to FavaTest in order to use its generated dll as a dependencie Build solution.Now, while the compiler heralds everything is fine, you should see that IntelliSense complains something on the event attachment row, with the following errore message:
IntelliSense: function "FavaTest::FavaClass::FavaEvent::add" cannot be called with the given argument list argument types are: (FavaTest::FavaClass::FavaDelegate ^) object type is: FavaTest::FavaClass ^
Ready to run package
I packaged all this in a side-test-standalone-solution zip file in order to make it possibile to unzip and run, but unfortunately (IMHO also questionably) I cannot post it here dued to SE guidelines, so it's up to you to make the debug context according to the above.
The question
I could also be missing something, but I used several times this algorithm before and it worked perfectly, now I'm experiencing this on two different machines (VS2013 and VS2015). Does this error apply to you too? And what's wrong with IntelliSense? It is such a simple scenario that I can't imagine I'm the only one experiencing it. I found no clue on the Internet though.
最满意答案
解决了。
它的出现是为了避免IntelliSense发疯,委托定义必须超出事件父类范围。 因此,在我的情况下,我必须做的就是将事情弄清楚(对于IntelliSense)是将代理移到类外添加public关键字,例如:
namespace FavaTest { public delegate void FavaDelegate(); // moved out of the class with "public" public ref class FavaClass : public System::Windows::Forms::UserControl { public: [...] // -- here defines very simple event -- // delegate row away from here event FavaDelegate^ FavaEvent; [...] } }Solved.
It came out that in order to avoid IntelliSense to get crazy, the delegate definition has to be out of the event parent class scope. So in my situation all I had to do to get things right (for IntelliSense) was to move delegate outside the class adding the public keyword, such as:
namespace FavaTest { public delegate void FavaDelegate(); // moved out of the class with "public" public ref class FavaClass : public System::Windows::Forms::UserControl { public: [...] // -- here defines very simple event -- // delegate row away from here event FavaDelegate^ FavaEvent; [...] } }Stubborn IntelliSense保持标记为false“无法使用给定的参数列表调用函数X”(Stubborn IntelliSense keeps flagging false “function X cannot be called with the given argument list”)环境
Visual Studio 2013和C ++ / CLI。
(ho / e)rror
我遇到了IntelliSense在符合编译器的行上出错的情况。 因此是假阳性。
错误如下:
IntelliSense:函数“<完全限定方法名称>”不能使用给定的参数列表调用 参数类型是: <期望参数类型> 对象类型是: <对象类型>
发生了什么
我做了一个UserControl。 在那里,我用相对代表声明了一个自定义事件。 我创建了一个表单。 在表单构造函数中,我分配了一个用户控件实例,并尝试将一个表单方法附加到控件自定义事件。
编译器说一切都好。 IntelliSense告诉我事件附件不匹配类型。
如何重现
我深入研究了这个问题并创建了一个重要的上下文来重现问题:
创建一个包含两个项目的解决方案: FavaTest (作为ClassLibrary)和FavaForm (作为控制台应用程序......或其他)。 在FavaTest创建一个名为FavaTest的UserControl,并将以下内容粘贴到FavaClass.h 。 #pragma once using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; namespace FavaTest { public ref class FavaClass : public System::Windows::Forms::UserControl { public: FavaClass(void) { InitializeComponent(); } // -- here defines very simple event -- delegate void FavaDelegate(); event FavaDelegate^ FavaEvent; protected: ~FavaClass() { if (components) { delete components; } } private: System::ComponentModel::Container ^components; #pragma region Windows Form Designer generated code void InitializeComponent(void) { this->SuspendLayout(); // // FavaClass // this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; this->Name = L"FavaClass"; this->Size = System::Drawing::Size(249, 147); this->ResumeLayout(false); } #pragma endregion }; } 在项目FavaForm创建一个名为FavaForm的Form,并将以下内容粘贴到LaForm.h namespace FavaForm { using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; public ref class LaForm : public System::Windows::Forms::Form { public: LaForm(void) { InitializeComponent(); // here simply allocs a FavaClass object and try to attach to FavaEvent event FavaTest::FavaClass ^item = gcnew FavaTest::FavaClass(); item->FavaEvent += gcnew FavaTest::FavaClass::FavaDelegate(this, &LaForm::onfava); } void onfava(){} protected: ~LaForm() { if (components) { delete components; } } private: System::ComponentModel::Container ^components; #pragma region Windows Form Designer generated code void InitializeComponent(void) { this->SuspendLayout(); // // LaForm // this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; this->ClientSize = System::Drawing::Size(368, 261); this->Name = L"LaForm"; this->Text = L"LaForm"; this->ResumeLayout(false); } #pragma endregion }; } 构建FavaTest 在FavaForm项目中, common properties添加对FavaTest的新引用,以便将其生成的dll用作依赖项 构建解决方案现在,虽然编译器预示一切都很好,但您应该看到IntelliSense在事件附件行上抱怨某事,并带有以下错误消息:
IntelliSense:函数“FavaTest :: FavaClass :: FavaEvent :: add”无法使用给定的参数列表调用 参数类型是: (FavaTest :: FavaClass :: FavaDelegate ^) 对象类型是:FavaTest :: FavaClass ^
准备运行包
我将所有这些打包在一个side-test-standalone-solution zip文件中,以便解压缩和运行,但不幸的是(恕我直言也有疑问)我不能在这里发布它的SE指南,所以这取决于你做根据上面的调试上下文。
这个问题
我也可能遗漏了一些东西,但之前我曾多次使用过这个算法并且它完美地运行了,现在我在两台不同的机器上遇到了这个问题(VS2013和VS2015)。 这个错误也适用于你吗? 智能感知有什么问题? 这是一个简单的场景,我无法想象我是唯一一个体验它的人。 我发现互联网上没有任何线索。
Environment
Visual Studio 2013 and C++/CLI.
The (ho/e)rror
I faced a situation of IntelliSense giving error on a compiler compliant row. Thus a false positive.
The error is the following:
IntelliSense: function "< full qualified method name >" cannot be called with the given argument list argument types are: < expected argument type > object type is: < object type >
What happened
I made a UserControl. There I declared a custom event with relative delegate. I created a form. In form constructor I alloc a my user control instance and try to attach a form method to the control custom event.
Compiler says everything is ok. IntelliSense tells me that event attachment mismatches types.
How to reproduce
I digged in the problem and created an essential context that should reproduce the problem:
Create a solution with two projects: FavaTest (as ClassLibrary) and FavaForm (as Console application...or whatever). In FavaTest create a UserControl whose name is FavaClass and paste the following in FavaClass.h. #pragma once using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; namespace FavaTest { public ref class FavaClass : public System::Windows::Forms::UserControl { public: FavaClass(void) { InitializeComponent(); } // -- here defines very simple event -- delegate void FavaDelegate(); event FavaDelegate^ FavaEvent; protected: ~FavaClass() { if (components) { delete components; } } private: System::ComponentModel::Container ^components; #pragma region Windows Form Designer generated code void InitializeComponent(void) { this->SuspendLayout(); // // FavaClass // this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; this->Name = L"FavaClass"; this->Size = System::Drawing::Size(249, 147); this->ResumeLayout(false); } #pragma endregion }; } In project FavaForm create a Form whose name is LaForm and paste the following in LaForm.h namespace FavaForm { using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; public ref class LaForm : public System::Windows::Forms::Form { public: LaForm(void) { InitializeComponent(); // here simply allocs a FavaClass object and try to attach to FavaEvent event FavaTest::FavaClass ^item = gcnew FavaTest::FavaClass(); item->FavaEvent += gcnew FavaTest::FavaClass::FavaDelegate(this, &LaForm::onfava); } void onfava(){} protected: ~LaForm() { if (components) { delete components; } } private: System::ComponentModel::Container ^components; #pragma region Windows Form Designer generated code void InitializeComponent(void) { this->SuspendLayout(); // // LaForm // this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; this->ClientSize = System::Drawing::Size(368, 261); this->Name = L"LaForm"; this->Text = L"LaForm"; this->ResumeLayout(false); } #pragma endregion }; } Build FavaTest In FavaForm project common properties add a new reference to FavaTest in order to use its generated dll as a dependencie Build solution.Now, while the compiler heralds everything is fine, you should see that IntelliSense complains something on the event attachment row, with the following errore message:
IntelliSense: function "FavaTest::FavaClass::FavaEvent::add" cannot be called with the given argument list argument types are: (FavaTest::FavaClass::FavaDelegate ^) object type is: FavaTest::FavaClass ^
Ready to run package
I packaged all this in a side-test-standalone-solution zip file in order to make it possibile to unzip and run, but unfortunately (IMHO also questionably) I cannot post it here dued to SE guidelines, so it's up to you to make the debug context according to the above.
The question
I could also be missing something, but I used several times this algorithm before and it worked perfectly, now I'm experiencing this on two different machines (VS2013 and VS2015). Does this error apply to you too? And what's wrong with IntelliSense? It is such a simple scenario that I can't imagine I'm the only one experiencing it. I found no clue on the Internet though.
最满意答案
解决了。
它的出现是为了避免IntelliSense发疯,委托定义必须超出事件父类范围。 因此,在我的情况下,我必须做的就是将事情弄清楚(对于IntelliSense)是将代理移到类外添加public关键字,例如:
namespace FavaTest { public delegate void FavaDelegate(); // moved out of the class with "public" public ref class FavaClass : public System::Windows::Forms::UserControl { public: [...] // -- here defines very simple event -- // delegate row away from here event FavaDelegate^ FavaEvent; [...] } }Solved.
It came out that in order to avoid IntelliSense to get crazy, the delegate definition has to be out of the event parent class scope. So in my situation all I had to do to get things right (for IntelliSense) was to move delegate outside the class adding the public keyword, such as:
namespace FavaTest { public delegate void FavaDelegate(); // moved out of the class with "public" public ref class FavaClass : public System::Windows::Forms::UserControl { public: [...] // -- here defines very simple event -- // delegate row away from here event FavaDelegate^ FavaEvent; [...] } }
发布评论