Nested iterators for printing generic list of generic lists

Let's say I have a generic list of a class 'Figure', and inside that 'Figure' class I have a generic list of 'Vertex' and a generic list of 'Faces'.

I want to print the content of the 'Figure' list along with the content of 'Vertex' list and 'Face' list, both inside each element of 'Figure' list

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
list<Figura> ls1;
	list<Figura>::iterator j;
	list<Vertice>::iterator k;
	list<Cara>::iterator l;
        
        //code after filling the lists
 
        for(j = ls1.begin(); j != ls1.end(); ++j)
		{
			cout << *j << endl;

			for(k = j; k; ++k) //It says that 'iterator k doesn't have a member called 'j'
			{
				//print elements of the Vertex list inside the Figure element
                        }
                }
		


I have that code but it doesn't work, can you help me? Thanks.

Oh, and the list of Vertex is called list<Vertice> vrtxlst, the Face list is called list<Cara> fcelst
Last edited on
Don't you mean
 
for (k = j->begin(); k != j->end(); ++k)
?
Does't work

class Figura has no member called 'begin'
Why did you say they were lists of lists, when in fact they're three completely unrelated lists?

1
2
3
4
5
6
for (auto &i : ls1){
    for (auto &j : vrtxlst){
        for (auto &k : fcelst){
        }
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <list>

struct Vertice { /* ... */ };
struct Cara { /* ... */ };

struct Figura
{
    std::list<Vertice> vrtxlst ;
    std::list<Cara> fcelst ;
    /* ... */
};

int main()
{
    std::list<Figura> figurae(6) ; // list of figurae
    // ...

    // range-based loops
    for( Figura& fig : figurae )
    {
        // ...
        for( Vertice& vertex : fig.vrtxlst )
        {
            // ...
        }

        for( Cara& face : fig.fcelst )
        {
            // ...
        }
    }

    // classic for loop with iterators
    for( auto figura_iter = figurae.begin() ; figura_iter != figurae.end() ; ++figura_iter )
    {
        // ...
        auto& vrtxlst = figura_iter->vrtxlst ;
        for( auto vertice_iter = vrtxlst.begin() ; vertice_iter != vrtxlst.end() ; ++vertice_iter )
        {
            // ...
        }

        auto& fcelst = figura_iter->fcelst ;
        for( auto cara_iter = fcelst.begin() ; cara_iter != fcelst.end() ; ++cara_iter )
        {
            // ...
        }
    }

}
Topic archived. No new replies allowed.