-1

So i'm trying to do a program where i input 3 values which are stored in a 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 dont know what the problem is. I think it might have something to do how i declare the header file and the other cpp file since i havent done alot 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 are LNK1120 1 unresolved externals and the second one is LNK2019 unresolved external symbol

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;
}
user3611818
  • 247
  • 2
  • 3
  • 13
  • What error do you get? – cadaniluk Nov 08 '15 at 16:36
  • Most probably a 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), but since you don't tell us what the error actually is :-P ... – πάντα ῥεῖ Nov 08 '15 at 16:37
  • My bad!, first error is: LLNK1120 1 unresolved externals and the second one is LNK2019 unresolved external symbol – user3611818 Nov 08 '15 at 18:54

1 Answers1

0

You can't use += in declaration. Just change string signature+=fname; to string signature=fname;