加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 链接器错误LNK2001

发布时间:2020-12-16 03:26:26 所属栏目:百科 来源:网络整理
导读:当我尝试创建一个对象时,我在Visual Studio中得到一个LNK2001错误,这是我认为的构造函数的问题,因为更改构造函数会更改错误. Customer bob("Bob","25 Bob Lane","01bob82","M","bob/bob/bob"); 这一行给出了这个错误: Error 1 error LNK2001: unresolved ex
当我尝试创建一个对象时,我在Visual Studio中得到一个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,class 
std::allocator<char> >,class
std::allocator<char> >)" (??0Customer@@QAE@V?$basic_string@DU?$char_traits@D@std@@V?
$allocator@D@2@@std@@0000@Z)    D:DropboxWorkC++C++ AssignmentC++ 
Assignmentdriver.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?";

    }

};

解决方法

如果你有链接错误,那么在语法上你的代码是正常的,否则你会得到编译器错误.

您应该检查(或添加)的是使用Customer类的项目的Dependencies属性中的路径.在VS中,您可以找到它“Project Properties-> Configuration Properties-> Linker-> Input-> Additional Dependencies”.似乎链接器无法通过Customer实现找到外部库.您可以成功编译项目,因为所有#include都是正确的,但由于依赖性,您在链接阶段失败.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读