My problem is this , Iwant make a list not of atomic elements, my list must be of agrgate data like a struct. With the container vector of the stl , the programa run okey with an iteratro eg. vitr i can access to dada memebers of struct like this
typedef struct
{
string salario;
int edad;
} persona;
....
.....
vector<persona>::iterator vitr;
for (vitr = v.begin(); vitr!=v.end(); vitr++)
{
cout << vitr->edad << "//";
cout << vitr->salario << "**";
}
but in the case of list of structs thera ara many problems:
example:
#include <iostream> // C++ I/O routines
#include <list> // The STL list class
#include<stdio.h>
#include <string>
using namespace std;
typedef struct MYSTRUCT
{
string valor2;
int valor1;
}dat;
void inserta(list<MYSTRUCT>& );
int main ()
{
list<dat> x;
randomize();
int t;
for (t=1;t<=20;t++)
{
inserta(x);
}
// Show all of the items now in the list.
list<dat>::iterator i;
for (i = x.begin(); i != x.end(); i++)
{
cout <<i->valor1<<"--";// the compiler Borland c++ v5 mark error there
cout << i->valor2 <<"--";// and there
}
cout << "\n\n\n";
cout << x.size();
cout << x.max_size();
}
void inserta(list<dat>& x)
{
dat pMySrtuct ;
pMySrtuct.valor1 = random(100)+1;
pMySrtuct.valor2 = "Buenas";
x.push_front(pMySrtuct);
}
the error message is :
Pointer to strcuture required on left side -> or ->*
Please tell how I can make a list of struct data and manage the items with iterator like a vector or deque
Thanks and sorry for my English.