我已经有另一个工作正常的库存,但由于某种原因,我的Paperclip库存无效。除了名称之外,两个库存几乎相同。 但是这个库存一直告诉我:错误E0757变量" Paperclip"不是类型名称。对于标记错误的行,我加粗了#34; Paperclip"。
我不确定如何解决这个问题。我用Google搜索,名称与我的头文件不一样。我的头文件是Inventory_Paperclip。错误说明它只在我的头文件中。
如果有人可以帮我指出正确的方向,或者给我一些指示我错误的地方,我们将不胜感激。如果您想查看我的主页或其他内容,请告诉我。 我在下面发布了Inventory_Paperclip的整个头文件:
#ifndef Inventory_Paperclip
#define Inventory_Paperclip
#include <iostream>
#include <vector>
#include <string>
using namespace std;
//Base Class
struct Paperclip
{
const int itemID;
const char *name;
Paperclip(int i, const char *n) : itemID(i), name(n) {}
virtual const char *typeName() const
{
return "";
}
virtual void print(ostream &out) const
{
out << typeName() << "(" << itemID << ")" << name << endl;
}
}; // end of Base Class
typedef vector<Paperclip *> Paperclips;
ostream &operator<<(ostream &, const Paperclip &);
ostream &operator<<(ostream &, const Paperclips &);
//Only execute in a situation where the code is cout << Paperclip
ostream &operator<<(ostream &out, const Paperclip &paperclip)
{
paperclip.print(out);
return out;
}
//Only execute in a situation where the code is cout << Paperclips
ostream &operator<<(ostream &out, const Paperclips &paperclips)
{
for (Paperclips::const_iterator it = paperclips.begin(); it != paperclips.end(); it++)
{
out << **it << endl;
}
return out;
}
//function to print out my Paperclip
void printPaperclip()
{
Paperclips paperclips;
paperclips.push_back(new Paperclip(1, "-- Paperclip"));
cout << "Inventory Items: " << endl;
cout << paperclips << endl;
return;
}
#endif