Hi there,

i have some problems with lists and structs (or perhaps pointers in general)
I am sorry if this was already discussed, but I really spend some time searching, but I am pretty new to programming and I did not find anything.


I need to use a list of structs, but it does not work as I expected.


the struct is

struct jubilee{
	unsigned int time;//
	unsigned int value;// 
	char unit; // 
};
list<jubilee> myJubilee;
	list<jubilee>::iterator it;
	jubilee first;
	first.time = anniversary_t +1000;
	first.unit = 's';
	first.value = 1000;

	cout << " " << first.time << " " << first.value << " " << first.unit << "\n";
	myJubilee.insert(myJubilee.begin(),1,first);
	
	jubilee second;
	second.time = anniversary_t + 2000;
	second.unit = 'm';
	second.value = 300;
	myJubilee.insert(myJubilee.begin(),1,second);
	
	it= myJubilee.begin();
	for(it = myJubilee.begin();it!=myJubilee.end();it++) 
		cout << " " << *it.time <<;//+++++++++++ this is the line that causes the problem
    cout << endl;

The compiler gives me the following error, referring to the line marked //++++++++++ like this:

error C2039: 'time' : is not a member of 'std::list<_Ty>::_Iterator<_Secure_validation>

I thought *it should point to each element of the list. And the list consists of jubilee elements, so *it.time should do the same as for example second.time

Thank you very much

leloo_d

You need to use the pointer cout << " " << it->time; or like this: cout << " " << (*it).time;

thank you very much -

In fact my problem was, that I did not know what my problem was about. Now i know that I will have to read a little bit more about pointers.

leloo_d

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.