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;
}