I have a secret in my arms. I am trying to learn managed C ++ coming from C # background and am confused. If I have a project that includes two classes, the base class Soup and the derived class TomatoSoup , which I compile as a static library (.lib), I get unresolved markers for virtual methods in Soup . Here is the code:
Abstracts.proj
Soup.h
namespace Abstracts { public ref class Soup abstract { public: virtual void heat(int Degrees); }; }
TomatoSoup.h
#include "Soup.h" namespace Abstracts { public ref class TomatoSoup : Abstracts::Soup { public: virtual void heat(int Degrees) override; }; }
TomatoSoup.cpp
#include "TomatoSoup.h" void Abstracts::TomatoSoup::heat(int Degrees) { System::Console::WriteLine("Soup on."); }
Main.proj
main.cpp
#include "TomatoSoup.h" using namespace System; int main(array<System::String ^> ^args) { Abstracts::TomatoSoup^ ts = gcnew Abstracts::TomatoSoup(); return 0; }
I get this link time error on Main.proj :
1>Main.obj : error LNK2020: unresolved token (06000001) Abstracts.Soup::heat
I tried setting
virtual void heat(int Degrees)=0;
I tried to realize heat in the base class
virtual void heat(int Degrees){}
and get an unpublished formal warning parameter error.
- I tried both 1 and 2 with no abstract keyword on the soup class
This problem is driving me crazy, and I hope to prevent it from driving other developers in the future.
UPDATE:. This worked with the Greg Hewgill name argument compilation method when TomatSoup :: heat was implemented in the header file, but the error returned when I moved the implementation to TomatoSoup.cpp. I changed the question to reflect this.
brian source share