0

So I've been getting this error in Visual Studios 2013 and I can't seem to figure out why.

Network.h:

#ifndef NETWORK_H
#define NETWORK_H
#include <iostream>
#include <vector>
#include "User.h"
#include "stdafx.h"
using namespace std;

class Network{
    vector<User*> users;
public:
    void sendMessage(istream&);
};

#endif

Network.cpp:

#include "stdafx.h"
#include <iostream>
#include <string>
#include <vector>
#include "Network.h"
using namespace std;

void Network::sendMessage(istream& ss){
    string msg, user;
    ss >> user;

    for (size_t i = 0; i < users.size(); i++){
        if (users[i]->getName() == user){
            users[i]->addMessage("this is a message");
        }
    }
}

User.h:

#ifndef USER_H
#define USER_H
#include <iostream>
#include <string>
#include <vector>
#include "stdafx.h"
using namespace std;

class User{
    vector<string> messages;
public:
    void addMessage(string), readMessages();
};

#endif

Error:

error LNK2019: unresolved external symbol "public: void __thiscall User::addMessage(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?addMessage@User@@QAEXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "public: void __thiscall Network::sendMessage(class std::basic_istream<char,struct std::char_traits<char> > &)" (?sendMessage@Network@@QAEXAAV?$basic_istream@DU?$char_traits@D@std@@@std@@@Z)    C:\Users\Ethan\Documents\Visual Studio 2013\Projects\SN Project\SN Project\Network.obj  SN Project

The error happens at the line "users[i]->addMessage("this is a message")". I've look around and I haven't found any solution to my problem (or whats even causing it). Thanks!

Ethan
  • 141
  • 1
  • 2
  • 9
  • "Visual Studios" would be an awesome movie studio name. "This summer, Visual Studios presents: Grosse Pointe Nulle. No `if`s, not `while`s, and no `return`." – Kerrek SB Jun 15 '14 at 15:36
  • Looks like you are missing User.cpp, with the implementation of addMessage. Also, where is the method getName() defined? – Jasper Jun 15 '14 at 15:36

0 Answers0