1

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?

2 Answers 2

2

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()

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks!! Yes the problem was the comparison.Final question: What should I do if I want to return other value than vector<Application>::iterator. to compare it to another method, for example NULL is error ... ?
Your suggested replacement is the same as the original code.
@AsteroidsWithWings thanks, that was embarrassing :)
Now it's backwards to what it should be
As for return NULL;... no, you can't.
|
1

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.

1 Comment

You can't construct a vector<Application>::iterator from NULL.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.