0

While working on my project in VS, I decided to split up the source into separate files. After trying to compile however, I got this 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 and found multiple similar questions. However, all of them had the same answer regarding a missing implementation. In my source however (unless I am horribly mistaken) the function mentioned in the error is properly 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();
};
Thsise Faek
  • 373
  • 1
  • 7
  • 20

1 Answers1

2

Your implementation file shouldn't be redefining the class. Here's what a 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...
}
Joel Cornett
  • 24,192
  • 9
  • 66
  • 88