Linker error LNK2001(链接器错误 LNK2001)
问题描述
当我尝试创建一个对象时,我在 Visual Studio 中收到 LNK2001 错误,我认为这是构造函数的问题,因为更改构造函数会更改错误.
When I try to create an object I get a LNK2001 error in Visual Studio, it's a problem with the constructor I think since changing the constructor changes the error.
Customer bob("Bob", "25 Bob Lane", "01bob82", "M", "bob/bob/bob");
这一行给出了这个错误:
This line gives this error:
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> >)" (??0Customer@@QAE@V?$basic_string@DU?$char_traits@D@V?
$allocator@DZ) D:DropboxWorkC++C++ AssignmentC++
Assignmentdriver.obj
包含构造函数的客户类:
Customer class that contains the constructor:
#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?";
}
};
推荐答案
如果你有链接错误,那么你的代码在语法上没有问题,否则你会得到编译器错误.
If you have linking error then syntactically your code is OK otherwise you'll get compiler errors.
您应该检查(或添加)的是使用 Customer 类的项目的 Dependencies 属性中的路径.在VS中,您可以找到项目属性->配置属性->链接器->输入->附加依赖项".似乎链接器找不到带有客户实现的外部库.您可以成功编译您的项目,因为所有#include 都是正确的,但您只是因为依赖关系而在链接阶段失败.
What you should check(or add) is path in Dependencies property of the project that uses Customer class. In VS you can find it "Project Properties->Configuration Properties->Linker->Input->Additional Dependencies". Seems that linker can't find the external library with Customer implementation. You can successfully compile your project cause all #include are correct but you fail on the stage of linking just because of dependencies.
这篇关于链接器错误 LNK2001的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:链接器错误 LNK2001
基础教程推荐
- 使用从字符串中提取的参数调用函数 2022-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 从 std::cin 读取密码 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01