我目前正在尝试创建一个列表,该列表将初始化100个item对象,但由于某种原因,编译器无法识别我的全局变量和数组。如有任何意见,将不胜感激。另外,如果你看到我做错了什么,批评是非常感谢的。
标题为我的列表:
#ifndef List_hpp
#define List_hpp
#include <stdio.h>
#include <string>
#include <iostream>
#include "Item.hpp"
using namespace std;
class List
{
private:
static int itemcount;
Item items[100];
public :
List(){
this->itemcount = 0;
};
void addItem(string, string, int, double);
void removeItem(string);
void display();
}; //End List Class
#endif /* List_hpp */CPP文件:
#include "List.hpp"
//This method will add a new item
void addItem(string name, string unit, int quantity, double price){
Item newItem(name, unit, quantity, price);
itemcount++;
}
void removeItem(string name){
}
void display(){
}发布于 2015-10-25 21:09:57
在类列表的CPP文件中,必须将类名放在每个函数实现之前,如下所示:
void List::addItem...
void List::removeItem...
void List::display..我认为addItem的实现还没有完成。您没有将新创建的项放在列表中。必须为类项声明副本构造函数,否则必须使用动态分配。
https://stackoverflow.com/questions/33334748
复制相似问题