0

I've got following classes:

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

As you can see I want to extern my method into additional class. The error is:

1>Milionerzy.obj : error LNK2020: unresolved token (06000004) Milionerzy.Form1::label1_Click

What is wrong?

Zomfire
  • 193
  • 1
  • 3
  • 15
  • You need to provide a definition for `Form1::label1_Click` or declare it pure virtual. – Captain Obvlious Dec 27 '16 at 21:52
  • I am trying pure virtual in class Form1 [code] virtual System::Void label1_Click(System::Object^ sender, System::EventArgs^ e) = 0; [/code] And I've got many errors. I'am using this solution: [link]http://stackoverflow.com/questions/2652198/difference-between-a-virtual-function-and-a-pure-virtual-function[/link] – Zomfire Dec 27 '16 at 22:23
  • 1> c:\users\michal\documents\visual studio 2010\projects\milionerzy\milionerzy\Form1.h(505) : see declaration of 'Milionerzy::Form1::label1_Click' 1> 'void Milionerzy::Form1::label2_Click(System::Object ^,System::EventArgs ^)' : is abstract – Zomfire Dec 27 '16 at 23:00

1 Answers1

0

You should probably remove label1_Click from Form1. There is no point in handling label1 click event at all, since you are thinking about making it pure virtual. Just handle it when you are able to.

If you want polymorphism in the handler declare another pure virtual function like this:

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();
    }
};
GeorgeT
  • 484
  • 3
  • 5
  • Thanks for your reply. But in this case I have to put all settings of each labels(or other elements) into first class to see it in design This must be inserted into class that child of(public System::Windows::Forms::Form). I don't want it. – Zomfire Jan 02 '17 at 13:47
  • In that case, remove all the abstract properties and handle label1 click event in Form1, calling the virtual (but not pure) OnLabelClick. So, Form1::OnLabelClick will do nothing and you will override it in Handlers class. – GeorgeT Jan 02 '17 at 14:19