linker - c++ unresolved external symbol? -
this question has answer here:
- separating class code header , cpp file 6 answers
while working on project in vs, decided split source separate files. after trying compile however, got error:
lnk2019 unresolved external symbol "public: __thiscall cs_rawuser::cs_rawuser(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,int)" (??0cs_rawuser@@qae@v?$basic_string@du?$char_traits@d@std@@v?$allocator@d@2@@std@@0h@z) referenced in function "void __cdecl mkuser(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?mkuser@@yaxv?$basic_string@du?$char_traits@d@std@@v?$allocator@d@2@@std@@00@z) i searched on google , found multiple similar questions. however, of them had same answer regarding missing implementation. in source (unless horribly mistaken) function mentioned in error defined.
cs_obj.cpp:
class cs_rawuser { private: string m_username; string m_password; int m_level; string compiledatabaseentry() { return "csec_instance_user:" + m_username + "," + m_password + "," + to_string(m_level); } public: cs_rawuser(string username, string password, int level) { m_username = username; m_password = password; m_level = level; } string username() { return m_username; } string password() { return m_password; } int level() { return m_level; } string compile() { return compiledatabaseentry(); } }; cs_obj.h:
class cs_rawuser { private: std::string m_username; std::string m_password; int m_level; std::string compiledatabaseentry(); public: cs_rawuser(std::string username, std::string password, int level); std::string username(); std::string password(); int level(); std::string compile(); };
your implementation file shouldn't redefining class. here's possible (correct) code looks like:
cs_obj.h:
class cs_rawuser { public: cs_rawuser(std::string username, std::string password, int level); }; cs_obj.cpp
#include "cs_obj.h" cs_rawuser::cs_rawuser(std::string username, std::string password, int level) { ... // initialization here... }
Comments
Post a Comment