gpt4 book ai didi

c++ - Apple Mach-O-Linker 错误 : Variable referenced from (line) not found in architecture x86-64

转载 作者:行者123 更新时间:2023-11-28 04:43:39 26 4
gpt4 key购买 nike

我正在为一个类项目编写 C++ 程序,在该项目中我将文件中的对象数据加载到列表中。我对其进行了设置,以便像在成员函数中一样完成数据读取,然后将该对象推送到列表,并重复,直到没有更多数据要加载。

我收到这个错误:

Undefined symbols for architecture x86_64:

"Product::Product(Product const&)", referenced from:

std::__1::list ::push_back(Product const&) in Week-2.o

ld: symbol(s) not found for architecture x86_64

clang: error: linker command failed with exit code 1 (use -v to see invocation)

主要功能:

Product temp;
list <Product> allProducts;

if (!temp.loadInitalData())
{
cout << "There is no Product data available. Try a different option: ";
cin >> choice;
repeat = true;
}
else {
while (temp.loadInitalData())
{
allProducts.push_back(temp); //This is where I'm getting the error
}
temp.viewMenu();
repeat = false;
}

产品的 loadInitalData() 函数:

bool Product::loadInitalData()
{
bool moreData = true;
fstream prodDatabase;
prodDatabase.open("ProductDatabase.csv", ios::out|ios::in|ios::binary);
if (!prodDatabase)
{
cout << "File could not be successfully opened\n";
moreData = false;
}
else
{
moreData = loadInitialItemData(prodDatabase);
}
return moreData;
}

我在我的 main.cpp 文件中链接了“Product.h”,以及 .有什么建议吗?

最佳答案

您缺少类 Product 的复制构造函数。关于编译器何时提供一个规则,如下所述:

http://en.cppreference.com/w/cpp/language/copy_constructor

但是如果复制 Product 对象是一项重要的操作,您可能仍然需要编写一个。

还可以考虑让您的列表成为 Product * 的列表(即指向 Product 的指针的列表)。这避免了复制,并且很可能是您真正想要的。

关于c++ - Apple Mach-O-Linker 错误 : Variable referenced from (line) not found in architecture x86-64,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49712921/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com