![]() |
| ||
| unresolved external symbol when using a hashtable class Hi I'm Josh and I'm new to these forums, and new to c++. I hope that I can get some great hints and help from the community. thank you in advance! I'm trying to create and use a hashtable class that uses a linked list for separate chaining. I've completed the code but I can't declare the class without generating these errors: Hashing error LNK2019: unresolved external symbol "public: __thiscall hashTable<class employeeType>::~hashTable<class employeeType>(void)" (??1?$hashTable@VemployeeType@@@@QAE@XZ) referenced in function _main Hashing error LNK2019: unresolved external symbol "public: __thiscall hashTable<class employeeType>::hashTable<class employeeType>(class employeeType const &,int)" (??0?$hashTable@VemployeeType@@@@QAE@ABVemployeeType@@H@Z) referenced in function _main This is the main program: // Hashing.cpp : Defines the entry point for the console application. here is the header for the hashtable class: #pragma once and here is the implementation for the hash table: #include "StdAfx.h" I thought maybe there was a problem with my employeeType class, but when I tried declaring hashTable<int> test(ITEM_NOT_FOUND); it didn't work either... what did I do wrong? and more importantly, how can I avoid making this mistake again? thank you for your time! |
| ||
| Re: unresolved external symbol when using a hashtable class >Hi I'm Josh Hi, Josh, I'm Julienne. >Hashing error LNK2019: unresolved external symbol "public: __thiscall >hashTable<class employeeType>::~hashTable<class employeeType>(void)" >(??1?$hashTable@VemployeeType@@@@QAE@XZ) referenced in function _main > >Hashing error LNK2019: unresolved external symbol "public: __thiscall >hashTable<class employeeType>::hashTable<class employeeType>(class employeeType const &,int)" >(??0?$hashTable@VemployeeType@@@@QAE@ABVemployeeType@@H@Z) referenced in function _main You've implemented the constructors and destructor, so my initial diagnosis is that you aren't linking with the implementation object file. What compiler are you using and how are you compiling the application? |
| ||
| Re: unresolved external symbol when using a hashtable class Quote:
|
| ||
| Re: unresolved external symbol when using a hashtable class >(lovely name) Thank you. :) >why can't I have the files separate? It sounds as if you don't have your project set up properly. What happens is that the header file contains declarations and the implementation files contain definitions. The header files are included in the implementation files only so that they can compile. Once the implementation files are compiled into object files, the object files are linked together into an executable. If one of the implementation files isn't compiled into an object file then the linking step will fail if the other implementation files use functions or objects defined in that implementation file. To recap, compilation requires that everything used be declared and linking requires that everything used be defined. >what is the proper way to do it? After starting Visual Studio, click on File, then New, and select Projet. From the New Project dialog, choose an Empty Project. This saves you from the irritating case where Visual Studio gives you precompiled headers (stdafx.h), and you can write code from scratch. Name the new project, and click OK. Now you'll see the Solution Explorer with the project you just created. This is where you set everything up. Right click on Header Files and add either a new item or an existing item depending on whether or not you've already written the header files, and do the same thing for Source Files. This will get your project set up for building so that the linking step works properly. Type Ctrl+F5, click Yes, and the project should build and then run without any problems. |
| ||
| Re: unresolved external symbol when using a hashtable class [QUOTE=Narue >what is the proper way to do it? After starting Visual Studio, click on File, then New, and select Projet. From the New Project dialog, choose an Empty Project. This saves you from the irritating case where Visual Studio gives you precompiled headers (stdafx.h), and you can write code from scratch. Name the new project, and click OK. Now you'll see the Solution Explorer with the project you just created. This is where you set everything up. Right click on Header Files and add either a new item or an existing item depending on whether or not you've already written the header files, and do the same thing for Source Files. This will get your project set up for building so that the linking step works properly. Type Ctrl+F5, click Yes, and the project should build and then run without any problems.[/QUOTE] I had tried that before. What I do is I make an empty project, then I make a header file that has the class definition. Then I make a cpp file that has the implementation. I put an #include in the cpp to include the header, and an #include in the main file also. I also put that #ifndef so it doesn't try to do it twice. but it still says unresolved external symbol. But when I cut everything from the cpp file and pasted it below the class definition in the .h file, IT WORKED. WHY?! I want them to be separate. I'm so confused... |
| ||
| Re: unresolved external symbol when using a hashtable class Without being there to see what you're doing wrong, it's hard to say. But my first guess is that you've created the files, but failed to add them to the project correctly. The only reason for that linker error is that the compiler sees your declarations, but the linker can't find the definitions. |
| ||
| Re: unresolved external symbol when using a hashtable class Quote:
thanks again for your help. |
| ||
| Re: unresolved external symbol when using a hashtable class >would that help to tell me what's wrong? Possibly, though your project file would also be helpful in this case. If you can't attach it then feel free to email it to me (PM for the address). |
| ||
| Re: unresolved external symbol when using a hashtable class Quote:
|
| All times are GMT -4. The time now is 7:34 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC