Chris
Chris

Reputation: 13

Linker Errors - Unresolved external symbol

Howdy. I am working on a C++ assignment for my class. I am almost done but can't seem to figure out these errors:

error LNK2001: unresolved external symbol "public: virtual void __thiscall HasQuarterState::dispense(void)const " (?dispense@HasQuarterState@@UBEXXZ) gumball.obj Gumball
error LNK2001: unresolved external symbol "public: virtual void __thiscall SoldState::turnCrank(void)const " (?turnCrank@SoldState@@UBEXXZ) gumball.obj Gumball
fatal error LNK1120: 2 unresolved externals C:\School Work\CS 492\Gumball\Debug\Gumball.exe Gumball

I went to MSDN and looked up LNK2001 error, but was provided with an overwhelming amount of info, and am afraid I can't figure out what is wrong given my limited experience with C++ from looking at the MSDN page.

But I do believe that the problems come from the way I have structured my program. My teacher said we may use one .cpp file if we wanted too, but I guess in the end I didn't know enough about Visual Studios/C++ to make this work. Ultimately I ran into some other problems that I had to solve that came from using one .cpp file.

The code/file in question is here: http://codepad.org/LpBeJT2Y

Its a big ole mess but this is what I have done:

As far as I can tell (with my limited knowledge of VS/C++), the code looks to be fine. Maybe there is something someone with more experience would catch. Any pointers on how to knock out this problem?

Thanks for the help.

Upvotes: 1

Views: 3766

Answers (2)

Warpin
Warpin

Reputation: 7043

In class SoldState, turnCrank is not defined. Change this:
void turnCrank() const;
To this:
void turnCrank() const { cout << "some implementation" << endl; }

and similarly for the other function.

Upvotes: 0

sean e
sean e

Reputation: 11925

You've declared dispense in HasQuarterState but have not defined it. The function has no body. Likewise with turnCrank in SoldState.

Upvotes: 1

Related Questions