Reputation: 17
I have the following:
#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;
}
}
I get this error:
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++)
Any suggestions?
Upvotes: 1
Views: 81
Reputation: 1545
On this line
for (it = this->ApplicationVector.begin(); it = this->ApplicationVector.end(); it++)
You are using the assignment equals not testing equality. Replace the test condition with it != this->ApplicationVector.end()
Upvotes: 2
Reputation: 60308
In the condition of your for loop, you are assigning to it
, instead of comparing against the result of end()
. You need to do:
for (it = this->ApplicationVector.begin();
it != this->ApplicationVector.end(); it++) {
if (*it == app)
break;
}
return it; // return found iterator, or 'end' if not found.
Note the !=
instead of =
.
Also, it's better to return outside of the for loop, otherwise the compiler will complain that you might not be returning a value from the function.
Upvotes: 1