in Education by
I have a mystery on my hands. I am trying to learn managed C++ coming from a C# background and have run into a snag. If I have a project which includes two classes, a base class Soup and a derived class TomatoSoup which I compile as a static library (.lib), I get unresolved tokens on the 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's on."); } Main.proj Main.cpp #include "TomatoSoup.h" using namespace System; int main(array ^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've tried setting virtual void heat(int Degrees)=0; I've tried implementing heat in the base class virtual void heat(int Degrees){} and get an unreferenced formal parameter warning treated as an error. I've tried both 1 and 2 with and without the abstract keyword on the Soup class This issue is driving me crazy and I hope to prevent it from driving other developers nuts in the future. UPDATE: This worked with Greg Hewgill's argument-name commenting method when the TomatoSoup::heat was implemented in the header file, but the error came back when I moved the implementation to TomatoSoup.cpp. I've modified the question to reflect that. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
The error you are getting (LNK2020) means the linker can't find a definition for the Abstracts.Soup::heat function anywhere. When you declare the function as virtual void heat(int Degrees); the linker will expect to find the function body defined somewhere. If you intend not to supply a function body, and require that subclasses eventually override the function, you should do as you indicated in solution 1: virtual void heat(int Degrees) = 0; This tells the compiler that you aren't going to implement the function. What happens when you do that? Also, with reference to your second solution: virtual void heat(int Degrees) {} the compiler is telling you that you don't reference the Degrees parameter within the function. One way to avoid this warning in C++ is to not give the parameter a name: virtual void heat(int /*Degrees*/) {} Supplying an empty implementation is a bit different from a pure virtual (= 0) declaration, though.

Related questions

0 votes
    I've created a seperate assembly with a class that is intended to be published through wmi. Then I' ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 24, 2022 in Education by JackTerrance
0 votes
    Visual Studio 2005 .Net Framework 2.0 I have the AjaxControlToolkit within my web application bin folder ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 2, 2022 in Education by JackTerrance
0 votes
    I have a case where a VB.Net winforms app needs to play WMV files from across the network. The ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 27, 2022 in Education by JackTerrance
0 votes
    I have a case where a VB.Net winforms app needs to play WMV files from across the network. The ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 25, 2022 in Education by JackTerrance
0 votes
    _____________ attack is the exploitation of the web-session & its mechanism that is usually managed with a ... -Cyber Security:,Cyber Security-Jobs:,Cyber Security Applications...
asked Oct 31, 2021 in Education by JackTerrance
0 votes
    So the problem is i don't get get a value from textbox field on GridView RowUpdating event. Here ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 8, 2022 in Education by JackTerrance
0 votes
    I'm modifying someone else's code where a query is performed using the following: DataSet ds = new ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 23, 2022 in Education by JackTerrance
0 votes
    I have been developing a webpage which uses n number of dropdownlists which are binding dynamically inside a ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 18, 2022 in Education by JackTerrance
0 votes
    I want create expression with reflection in c#. I am target script is: using (var service = new ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 14, 2022 in Education by JackTerrance
0 votes
    I have a Login control placed inside LoginView control contained within a PANEL. I want to set login button ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 8, 2022 in Education by JackTerrance
0 votes
    All How can I download a file so the user sees that it is downloading (like with a stream?) I ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 2, 2022 in Education by JackTerrance
0 votes
    I'm trying to add data into my Access database in Visual Basic, but I encount this error when I ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 26, 2022 in Education by JackTerrance
0 votes
    I'm working on a DNN skin using Christoc's DNN templates and when I create a normal ASP.NET ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 26, 2022 in Education by JackTerrance
0 votes
    I'm trying to generate an 837P EDI file using EDIDev. I was able to generate 4 other 837P files ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 19, 2022 in Education by JackTerrance
0 votes
    I have tried many solution online but I am unable to fix. First off all i check in bin and it ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
...