开发者

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:

  • Declare a class named GumballMachine (no definition)
  • Define a class named State (which in turn has a pointer to a GumballMachine)
  • Defined several other state classes which inherit from State
  • Define class GumballMachine
  • Defined several functions that were excluded from the original definitions of the other state classes. This is because these functions relied on defined functions of GumbballMachine and wouldn't work until the GumballMachine functions were defined.
  • void main()

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.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜