LNK2001 Error

Jun 28, 2011 at 12:59am
Here is the error:
1
2
3
4
5
6
7
8
1
1>  Main.cpp
1>c:\users\david\documents\visual studio 2010\projects\employee database\main.cpp(56): warning C4018: '<' : signed/unsigned mismatch
1>c:\users\david\documents\visual studio 2010\projects\employee database\main.cpp(67): warning C4018: '<' : signed/unsigned mismatch
1>Engineer.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall Employee::Save(class std::basic_ofstream<char,struct std::char_traits<char> > &)" (?Save@Employee@@UAEXAAV?$basic_ofstream@DU?$char_traits@D@std@@@std@@@Z)
1>Manager.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall Employee::Save(class std::basic_ofstream<char,struct std::char_traits<char> > &)" (?Save@Employee@@UAEXAAV?$basic_ofstream@DU?$char_traits@D@std@@@std@@@Z)
1>Researcher.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall Employee::Save(class std::basic_ofstream<char,struct std::char_traits<char> > &)" (?Save@Employee@@UAEXAAV?$basic_ofstream@DU?$char_traits@D@std@@@std@@@Z)
1>C:\Users\david\Documents\Visual Studio 2010\Projects\Employee Database\Debug\Employee Database.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


Ill post code if you guys need it.
Jun 28, 2011 at 1:07am
is the definition (not declaration) of employee present and is it all included into the main function. in other words did you leave employee::save empty with no definition.
Last edited on Jun 28, 2011 at 1:10am
Jun 28, 2011 at 1:11am


Im assuming that was question so:
Employee is a class so yeah its defined and it's included in the main function by using one of its methods.
Jun 28, 2011 at 1:15am
so inside employee::Save there is code and it is not empty right.
Jun 28, 2011 at 1:22am
actually it is empty.

it is a virtual function and i meant for the whole Employee class to be abstract and use it only to derive other classes from it. In the other classes the Save function is defined.

Im guessing i have to define it in the Employee class, so how would i do that if Employee never has an instances?
Jun 28, 2011 at 1:33am
For it to be pure virtual, you must declare it like this:
virtual void Save(ofstream&) = 0;
Note the =0, this makes it pure virtual rather than just another virtual function, meaning the class will then be abstract. Being abstract also means you can't instantiate a generic Employee class, but you can instantiate any non-abstract classes that derive from it, and polymorphism will still work just fine.
Jun 28, 2011 at 1:45am
Thanks L B!
Topic archived. No new replies allowed.