0

I'm trying to do a program where I input 3 values which are stored in an object and a fourth value which I generate from 2 of the other values and I store that object into a vector.

That problem is that I'm getting an error from the generateSignature() function and I don't know what the problem is. I think it might have something to do with how I declare the header file and the other .cpp file since I haven't done a lot of programming involving these. So I'm asking to see if anyone can see anything wrong with what I have done so far.

The errors i'm getting is:

LNK2019 unresolved external symbol "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl generateSignature(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::vector<struct Data,class std::allocator<struct Data> > &)" (?generateSignature@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@0AAV?$vector@UData@@V?$allocator@UData@@@std@@@2@@Z) referenced in function _main    ProjektKurs C:\Users\Fredrik\documents\visual studio 2015\Projects\ProjektKurs\ProjektKurs\ProjektKurs.obj  

Project.cpp:

#include "stdafx.h"
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include "constants.h"
using namespace std;
      int main()
            {
                    vector<Data> dataVector;
                    struct Data newdata;
                    newdata.fname = "testfname";
                    newdata.lname = "testlname";
                    //add signature
                    newdata.signature = generateSignature("testfname","testlname",dataVector);
                    newdata.height = 1.85;
                    dataVector.push_back(newdata);
                    for (int i = 0; i < dataVector.size();i++) {
                        cout << dataVector.at(i).fname << " " << dataVector.at(i).lname + " " + dataVector.at(i).signature << " " << dataVector.at(i).height << endl;
                    }
            }

constants.h:

#pragma once
#ifndef CONSTANTS_H
#define CONSTANTS_H
#include <string>
#include <vector>
using namespace std;
struct Data {
    string fname;
    string lname;
    string signature;
    double height;
};
string generateSignature(string fname, string lname, vector<Data>& data);

#endif

constants.cpp:

#include "stdafx.h"
#include "constants.h"
#include <iostream>
#include <string>
#include <vector>


using namespace std;
string generateSignature(string fname, string lname, vector<Data>& data) {
    string signature+=fname;
    signature+="test123";

    //some random code for the vector
    return signature;
}
Biffen
  • 6,249
  • 6
  • 28
  • 36
user3611818
  • 247
  • 2
  • 3
  • 13
  • 1
    When asking question about build error, please include the *complete* and *unedited* error output in the question. Please edit your question to include that information. – Some programmer dude Nov 09 '15 at 12:06
  • 3
    Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Biffen Nov 09 '15 at 12:08

0 Answers0