Visual C ++ 2010错误:LNK2020未解析的令牌

时间:2016-12-27 21:18:05

标签: 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() {}
};

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

正如您所看到的,我想将我的方法extern到其他类中。 错误是:

  

1> Milionerzy.obj:错误LNK2020:未解析的令牌(06000004)Milionerzy.Form1 :: label1_Click

有什么问题?

1 个答案:

答案 0 :(得分:0)

您应该从Form1中删除label1_Click。处理label1点击事件毫无意义,因为您正在考虑将其设为纯虚拟事件。只要你能够处理就可以了。

如果你想在处理程序中使用多态,则声明另一个纯虚函数,如下所示:

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();
    }
};