I wanna store objects on vectors. But I do not know why it does not work.
#include <iostream>
#include <vector>
using namespace std;
I have a Persona class in the Persona.h file. And it only has two method: The default constructor and a method called mensaje(), both are public and it does not have any private member.
#include "Persona.h"
int main()
{
vector<Persona> personas;
Persona persona1;
Persona persona2;
personas.push_back(persona1);
personas.push_back(persona2);
vector<Persona>::const_iterator p;
for(p = personas.begin(); p <= personas.end(); p++) {
Here is where I get the error message
p.mensaje();
}
}
I think problem is the way that I am trying to call 'p'. Is right that I try to use const_iterator instead of any other type?
p <= personas.end()
should be<
. Alsop
is an iterator so you should use->
, not.
on the iterator to access the members of the class.!=
, really.