LNK2020 error: unresolved token (06000002) in Visual C ++

I am creating a new abstract class in C ++ / CLI and encountered a strange error. There are many questions like this, but none of the answers helped me.

In this new class, I get the following error:

error LNK2020: unresolved token (06000002) Foo::execute 

This is the h file:

 #pragma once using namespace System::IO::Ports; using namespace System; public ref class Foo { protected: SerialPort^ port; public: Foo(SerialPort^ sp); virtual array<Byte>^ execute(); }; 

This is the cpp file:

 #include "StdAfx.h" #include "Foo.h" Foo::Foo(SerialPort^ sp) { this->port = sp; } 

Note that when I comment out the line virtual array<Byte>^ execute(); Everything compiles fine. Also, when I remove the virtual modifier and add the execute() implementation to the cpp file, it also works.

+4
source share
2 answers

You yourself have already answered:

Also, when I remove the virtual modifier and add the execute () implementation to the cpp file, it also works.

You have declared the execute method in the header, but its implementation is missing. This is what the linker error tells you. In this case, an expression like virtual does not matter.

If you want to create an abstract class, you can find more information in numerous articles on the Internet (for example, Wikibooks: Abstract classes )

+6
source

You must either implement the method or remove the declaration from the header. (the virtual keyword in this case does not matter)

Please ask a question if you have one.

+3
source

All Articles