gpt4 book ai didi

c++ - C++上的 vector 迭代器

转载 作者:行者123 更新时间:2023-12-02 09:54:04 25 4
gpt4 key购买 nike

我有以下内容:

#ifndef APPSYSTEM_H
#define APPSYSTEM_H
#include "Application.h"
#include <iostream>
#include <exception>
#include <vector>
#include <iterator>

using namespace std;

class AppSystem{
private:
vector<Application> &ApplicationVector;
public:
AppSystem(); //AppSystem Constructor
AppSystem(const AppSystem &); //Copy constructor
void setApplicationVector(vector<Application> &); //Set the AppSystem's Application Vector
vector<Application> getApplicationVector(); //Get the AppSystem's Application Vector
void PushAppToApplicationVector(Application &) const; //Push Data to ApplicationVector
Application &PopAppFromApplicationVector(Application &) const; //Pop Data from ApplicationVector
vector<Application>::iterator FindAppToApplicationVector(Application &) const; //Find if Data belongs to ApplicationVector
void DeleteAppFromApplicationVector(Application &); //Delete Data from ApplicationVector
void ClearAllpicationVector(); //Clear all data from ApplicationVector
virtual ~AppSystem(); //Destructor
};

#endif /* APPSYSTEM_H */

// APPSYSTEM.cpp file

//Find if Data belongs to ApplicationVector
vector<Application>::iterator AppSystem::FindAppToApplicationVector(Application &app) const{
vector<Application>::iterator it;
for (it = this->ApplicationVector.begin(); it = this->ApplicationVector.end(); it++){
if (*it == app){
return it;
}
}

我收到此错误:
AppSystem.cpp:56:51: error: could not convert '(it = (&((const AppSystem*)this)->AppSystem::ApplicationVector)->std::vector<_Tp, _Alloc>::end<Application, std::allocator<Application> >())' from 'std::vector<Application>::iterator {aka __gnu_cxx::__normal_iterator<Application*, std::vector<Application> >}' to 'bool'
for (it = this->ApplicationVector.begin(); it = this->ApplicationVector.end(); it++)

有什么建议么?

最佳答案

在这条线上

for (it = this->ApplicationVector.begin(); it = this->ApplicationVector.end(); it++)

您正在使用分配等于而不是测试相等性。将测试条件替换为 it != this->ApplicationVector.end()

关于c++ - C++上的 vector 迭代器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61843277/

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