Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Visual studio 2010 visualc&x2B+;2010错误:LNK2020未解析令牌_Visual Studio 2010_C++ Cli_Linker Errors - Fatal编程技术网

Visual studio 2010 visualc&x2B+;2010错误:LNK2020未解析令牌

Visual studio 2010 visualc&x2B+;2010错误:LNK2020未解析令牌,visual-studio-2010,c++-cli,linker-errors,Visual Studio 2010,C++ Cli,Linker Errors,我有以下课程: public ref class Form1 : public System::Windows::Forms::Form { //[...] protected: System::Void label1_Click(System::Object^ sender, System::EventArgs^ e); }; public ref class Functions : public Form1 { protected: void Example() {} }; publ

我有以下课程:

public ref class Form1 : public System::Windows::Forms::Form
{
//[...]
protected:
System::Void label1_Click(System::Object^  sender, System::EventArgs^  e);
};

public ref class Functions : public Form1
{
protected:
void Example() {}
};

public ref class Handlers : public Functions
{
private:
  System::Void label1_Click(System::Object^  sender, System::EventArgs^  e)
  {
    Example();
  }
};
正如您所看到的,我想将我的方法扩展到其他类中。 错误是:

1> Milionerzy.obj:错误LNK2020:未解析令牌(06000004)Milionerzy.Form1::label1\u单击


怎么了?

您可能应该从表单1中删除label1\u单击。处理label1 click事件毫无意义,因为您正在考虑将其变成纯虚拟的。只要你能处理好它

如果要在处理程序中使用多态性,请声明另一个纯虚拟函数,如下所示:

public ref class Form1 abstract: public System::Windows::Forms::Form 
{
//[...]
protected:
     virtual void OnLabel1Click()=0;
};

public ref class Functions : public Form1
{
protected:
    void Example() 
    {
    }
    virtual void OnLabel1Click() override
    {
        Example();
    }
};

public ref class Handlers : public Functions
{
private:
    System::Void label1_Click(System::Object^  sender, System::EventArgs^  e)
    {
        OnLabel1Click();
    }
};

您需要为
Form1::label1\u Click提供定义,或者将其声明为纯虚拟。我正在类Form1[code]virtual System::Void label1\u Click(System::Object^sender,System::EventArgs^e)=0;[code]我有很多错误。我正在使用这个解决方案:[link]1>c:\users\michal\documents\visualstudio 2010\projects\milionerzy\milionerzy\Form1.h(505):参见“milionerzy::Form1::label1\u Click”的声明“void milionerzy::Form1::label2\u Click(System::Object^,System::EventArgs^)”:谢谢您的回复。但在这种情况下,我必须将每个标签(或其他元素)的所有设置放在第一个类中,以便在设计中看到它。这必须插入到(public System::Windows::Forms::Forms)的子类中。在这种情况下,删除所有抽象属性,并在Form1中处理label1 click事件,调用虚拟(但不是纯)OnLabelClick。所以,Form1::OnLabelClick不会做任何事情,您将在Handlers类中重写它。