类错误 C3867 中的 stl 列表
stl list in a class error C3867
我正在做一个项目,该项目读取食谱并将其与您的储藏室(用户定义)中的内容进行比较。
我希望通过在线搜索来减少大部分问题,但有一个特别烦人。
每当我设置迭代器list::迭代器 listThatIsInClass;等于开始或结束,Visual Studio Express 2013 给了我一个 C3867 错误。执行逻辑运算时也有 C2678 错误,小于 etc。
下面是一个不起作用的功能
void extractData::compareInventoryRecipe()
{
string recipIng = " ";
string invenIng = " ";
double recipAm = 0;
double invenAm = 0;
double x = 0;
double y = 0;
list<int>::iterator invenIterAmount;
invenIterAmount = inventoryAmount.begin;
list<int>::iterator recipeIterAmount;
recipeIterAmount = recipeAmount.begin;
for (list<int>::iterator recipeIter = recipeFoodName.begin; recipeIter != recipeFoodName.end; ++recipeIter)
{
++recipeIterAmount;
for (list<int>::iterator invenIter = inventoryItem.begin; invenIter != inventoryItem.end; ++invenIter)
{
++invenIterAmount;
recipIng = *recipeIter;
invenIng = *invenIter;
recipAm = *recipeIterAmount;
invenAm = *invenIterAmount;
if (recipIng.compare(invenIng) == 0)
{
if (invenAm < recipAm)
{
x += (invenAm / recipAm);
neededAmount.push_back(invenAm - recipAm);
neededItem.push_back(invenIng);
}
else
{
x += 1;
recipeFoodName.remove(invenIng);
recipeAmount.remove(invenAm);
}
break;
}
else
continue;
}
y += 1;
}
setPercentOnHand((x * 100) / y);
}
下面是头文件。如您所见,所有列表都受到保护,因为存在一个较早的问题,即函数不私下访问它们。
class extractData
{
protected:
list<string> recipeMeasurmentType
list<string> recipeFoodName;
list<double> recipeAmount;
list<string> inventoryItem;
list<double> inventoryAmount; // do i need regular int and string as well?
list<string> neededItem;
list<double> neededAmount;
list<string> measurmentLetter;
private:
string recipeTitle;
int choice;
double percentOnHand;
我确实尝试制作一个包含迭代器的模板(我在这方面不是很有经验)。下面是模板,我不知道如何处理它。它是头文件中的公共类。
template <class T>
void iterators(list<T> data)
{
typename list<T>::iterator begin();
typename list<T>::iterator end();
typename list<T>::const_iterator begin() const;
typename list<T>::const_iterator end() const;
}
有人可以帮我吗?谢谢。
在你的类定义中,你已经将你的列表声明为double
列表,例如
list<double> inventoryAmount;
然后在extractData::compareInventoryRecipe()
中,您将为int
列表创建一个迭代器:
list<int>::iterator invenIterAmount;
invenIterAmount = inventoryAmount.begin;
除了begin
上缺少()
(导致第一个错误 C3867)之外,分配给迭代器时存在类型不匹配 - 列表需要是相同的类型,因此
list<double>::iterator invenIterAmount;
invenIterAmount = inventoryAmount.begin();
应该纠正问题。
您的其他一些列表也存在类似的问题,例如 recipeAmount
.
你忘了告诉我们那些神秘的错误代码是什么意思以及它们指的是哪些行。首先是
function call missing argument list
因为您忘记在对begin
和end
函数的各种调用之后放置()
:
invenIterAmount = inventoryAmount.begin();
^^
第二个是
no operator defined which takes a left-hand operand of type 'type'
这意味着您正在将某种运算符应用于未定义该运算符的类型。我猜这来自像 recipeIter != recipeFoodName.end
这样的比较,当您添加缺失的()
时,这将得到修复。
通常,在询问错误时,请包含确切的错误消息,并准确指出导致错误的代码行,并有足够的代码来提供我们可以用来重现错误的测试用例。然后,我们不必猜测错误与您的代码有何关系。
- 如何检查C ++ STL列表是否为回文?
- 清除 C++ 中的指针的 STL 列表
- 在Visual Studio 2013中编译的STL列表代码在Visual Studio 2019中给出了错误.想知道原
- 使用.txt文件填充 STL 列表不起作用
- 为 STL 列表编写选择排序
- 如何从 STL 列表中删除结构记录
- C++如何将 STL 列表传递给函数
- 漂亮的打印不适用于C ++ STL列表
- 在C++中,是否可以引用像C++中的stl列表这样的数据结构部分
- 如何根据STL列表中的元素数量分配内存
- 我怎么知道,如果我在 STL 列表中找到了我搜索的号码
- 打印列表列表C++ STL 列表
- 我们可以在穿越时插入STL列表吗?
- 使用 c++ 的 STL 列表 ..在传递列表指针的数组中
- 使用 C++11 迭代语法时从 STL 列表中删除
- 如何使用静态 stl 列表的迭代器
- 如何更改 stl 列表中项的值
- STL列表,删除所有奇数
- 如何将函数中的stl列表传递为C 中的参数
- 如何将结构添加到STL列表中