當我嘗試創建一個對象時,在Visual Studio中出現LNK2001錯誤,這是構造函數的問題,我認爲因爲更改構造函數會更改錯誤。鏈接器錯誤LNK2001
Customer bob("Bob", "25 Bob Lane", "01bob82", "M", "bob/bob/bob");
此行給出了這樣的錯誤:
Error 1 error LNK2001: unresolved external symbol "public: __thiscall
Customer::Customer(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::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::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> >)" ([email protected]@[email protected][email protected][email protected]@[email protected]@V?
[email protected]@[email protected]@[email protected]@[email protected]) D:\Dropbox\Work\C++\C++ Assignment\C++
Assignment\driver.obj
Customer類包含構造函數:
#pragma once
#include "l_list.h"
#include "Account.h"
#include <string>
using namespace std;
class Customer
{
private:
l_list<Account> accounts;
string name;
string address;
string telNo;
string sex;
string dob;
public:
Customer(string name, string address, string telNo, string sex, string dob)
{
Customer::name = name;
Customer::address = address;
Customer::telNo = telNo;
Customer::sex = sex;
Customer::dob = dob;
}
void createAccount()
{
cout << "What type of account?";
}
};
這通常意味着您的頭文件包含錯誤版本或與錯誤版本的運行時庫鏈接。您的INCLUDE和LIB路徑應該指向相同的SDK版本。 – Flot2011
這是一個鏈接器錯誤。所以,看起來你的項目不包含'Customer.cpp'。或者你正在通過舊的(或錯誤的)庫使用'class Customer'。 – qehgt