-1
所以我想要做一個程序,其中我輸入3個值存儲在一個對象和第四個值,我從2其他值生成,我將該對象存儲到一個向量。 這個問題是,我從生成簽名函數得到一個錯誤,我不知道問題是什麼。我認爲這可能有些事要做,因爲我沒有做過很多涉及這些的編程,所以我聲明瞭頭文件和其他cpp文件。所以我要問,看看有沒有人可以看到我到目前爲止所做的事情有什麼問題。 我發現了錯誤LNK1120 1無法解析的外部,而第二個是LNK2019解析的外部符號聲明頭文件和cpp文件C++
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;
}
您會得到什麼錯誤? – Downvoter
最有可能是[什麼是未定義的引用/無法解析的外部符號錯誤,我該如何解決它?]的副本(http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-外部符號錯誤和怎麼辦我修復),但既然你不告訴我們什麼是錯誤實際上是:-P ... –
我的不好!,第一個錯誤是:LLNK1120 1無法解析的外部和第二個是LNK2019未解析的外部符號 – user3611818