list inside list Iter1->list2.push_back()?

I'm trying to add values to a list inside a list after looping through the lists with iterators.
Here is an example of the structs used as the types for the lists.
1
2
3
4
5
6
7
8
9
10
11
12
13
	struct type2
	{
		string sname;
		int angle1;
		int angle2;
	};

	struct type1
	{
		string name;
		string sname;
		list<type2> list2;
	};

Here is an example of what I'm trying to do.
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
	list<type1>::const_iterator Iter1 = list1->cbegin();
	while ( Iter1 != list1->cend() )
	{
		if ( Iter1->sname == a1 )
		{
			bool exists = false;
			list<type2>::const_iterator Iter2 = Iter1->list2.cbegin();
			while ( Iter2 != Iter1->list2.cend() )
			{
				if ( ( Iter2->sname == a1 ) && ( Iter2->angle1 == atoi( angle1.c_str() ) ) && ( Iter2->angle2 == atoi( angle2.c_str() ) ) )
				{
					exists = true;
					break;
				}
				Iter2++;
			}

			if ( exists == false )
			{
				type2 val = { a1 , atoi( angle1.c_str() ), atoi( angle2.c_str() ) };
				Iter1->list2.push_back( val );
			}
			break;
		}
		Iter1++;
	}

at this line
Iter1->list2.push_back( val );

it says
no instance of overloaded function
for push_back();

I think it is trying to use a non existant push_back function in one of the types. It is probably something simple, but I don't understand how to fix this.

EDIT: the first list is passed to the function by reference. this code is in that function.
Last edited on
You are using a const iterator so Iter1->list2 will give you a const list that you can't add new elements to.
Can you have a iterator inside a constant iterator, or do both iterators need to not be constant?
EDIT: Nevermind I found the answer. You can have const_iterator inside a iterator, but you can't have iterator inside a const_iterator.
Last edited on
Topic archived. No new replies allowed.