c++ - 未定义的函数引用错误?

标签 c++ function reference undefined

<分区>

我看到其他类似的问题被问到,但我无法弄清楚问题是什么。我在库存类中有一个声明:

class Inventory
{
   Public:
      void print();
      void sell(Item*);
      void add();
      void find(string);
   Private:
      Item* first;
}

然后在 inventory.cpp 中我有:

 void sell(Item* item_name)
 {
    ..........................
 }

错误来自于在 main() 中调用它:

Inventory store_inventory;
Item* cur_item;
cout<<"Item name: ";
string name;
cin>>name;
cur_item = find(name); //find returns Item*

store_inventory.sell(cur_item);

错误是卖出电话的一行。有什么想法吗?

最佳答案

定义需要说明是Inventory的成员函数:

void Inventory::sell( Item* item_name )
{
    // ...
}

此外,find() 函数也存在问题。您将其声明为 void 成员函数,但使用 at 就好像它是一个返回 Item* 的自由函数。

关于c++ - 未定义的函数引用错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28754646/

相关文章:

javascript - var functionName = function() {} vs function functionName() {}

c++ - 铸件内的符号

c++ - Windows 中的 Qt Designer 以及 Qt Creator

c++ - 在opencv中将2张图像与透明蒙版结合起来

c++ - namespace 函数未链接

c# - 引用 IBM.Data.DB2 中的代码会使该程序集对我的解决方案的其余部分不可用

c++ - 空引用 - C++ 标准中的位置

c++ - 完美的单例设计模式

c++ - 为什么一定要Forward声明一个类,在一个头文件中包含对应的头文件

c++ - 一次发布多个数据