469,635 Members | 1,852 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,635 developers. It's quick & easy.

LNK2019 on you own non-static class member functions Oo

I am having trouble with a LNK2019 on a member function.

Here is the error:
Expand|Select|Wrap|Line Numbers
  1. main.obj : error LNK2019: unresolved external symbol "public: void __thiscall Stat::openFile(char *)" (?openFile@Stat@@QAEXPAD@Z) referenced in function _main
As all functionality is made by me or uses simply c++'s main libraries through its header files, there was no need to add any *.lib files.

This is using Visual Studio .NET 2005.

Here is main:

Expand|Select|Wrap|Line Numbers
  1. #include "Stat.h"
  2.  
  3. int main(int argc, char* argv[])
  4. {
  5.   Stat* stat = new Stat();
  6.  
  7.   stat->openFile(argv[1]);
  8.  
  9.   return 0;
  10. }
Here is Stat.h:

Expand|Select|Wrap|Line Numbers
  1. #ifndef STAT_H
  2. #define STAT_H
  3.  
  4. #include "IndexedLinkList.h"
  5.  
  6. class Stat
  7. {
  8. public:
  9.  
  10.   Stat();
  11.   ~Stat();
  12.  
  13.   void openFile(char*);
  14.  
  15. private:
  16.  
  17.   IndexedLinkList* list;
  18. };
  19.  
  20. #endif
Please let me know what needs to be done. If there is any more information you require, please ask.

Thank you
May 2 '07 #1
6 2882
weaknessforcats
9,208 Expert Mod 8TB
I see the declaration:

void openFile(char*);

as a member function of the Stat class.

The compiler has no problem with this. It just marks the function as an unresolved external reference. The linker picks up on this and looks for the code for the function and can't find it. Neither can I.

Where is the code for this function? You need to add it to the build probably by adding the source file with the code to your IDE project.
May 2 '07 #2
all of the files are included with the project

Here is Stat.cpp:

Expand|Select|Wrap|Line Numbers
  1. #include "IndexedLinkList.h"
  2. #include "Stat.h"
  3.  
  4. #include <iostream>
  5. #include <fstream>
  6.  
  7. using namespace std;
  8.  
  9. Stat::Stat()
  10. {
  11.   list = new IndexedLinkList();
  12. }
  13.  
  14. Stat::~Stat()
  15. {
  16.   delete list;
  17. }
  18.  
  19. void openFile(char* f)
  20. {
  21.   fstream file(f, ios_base::binary | ios_base::in);
  22.  
  23.   // do stuff
  24. }
May 2 '07 #3
weaknessforcats
9,208 Expert Mod 8TB
This function:
Expand|Select|Wrap|Line Numbers
  1. void openFile(char* f)
  2. {
  3.   fstream file(f, ios_base::binary | ios_base::in);
  4.  
  5.   // do stuff
  6. }
  7.  
is not a member function of the Stat class.

Where is the Stat::openFile() function ???
May 2 '07 #4
wow, cant believe I missed that...
I suppose I should read my code a little closer.

thanks for your patience.
May 2 '07 #5
weaknessforcats
9,208 Expert Mod 8TB
One day you will understand why I saw that so quickly. Just don't tell anyone, OK?
May 3 '07 #6
svlsr2000
181 Expert 100+
C++ uses name mangling to manage overloaded functions. All the Functions names are mangled during compile time.

If you are more intrested in knowing about the linker error, you can read more on name mangling.
http://www.kegel.com/mangle.html
May 3 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by sheep | last post: by
reply views Thread by Droopy Toon | last post: by
3 posts views Thread by Chris B | last post: by
7 posts views Thread by solarin | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.