0
What's the error in compiling const iterator
Please refer code below: Can anyone suggest how to remove the errors ? https://code.sololearn.com/c2pTQZJ1I4NE/?ref=app
4 Respostas
+ 2
It's not an error because the const_iterator returns a 'Test* const', not a 'const Test*'.
Which is pretty much the same as if you return const int from a function, as in you can still assign it to a non const int.
If you want it to be const either have a container of 'const Test*' objects or explicitly add const on line 32.
0
The first error seems to get corrected if I change line 40 from
itr->display();
To
(*itr)->display();
After that, errors are due to attempts to access freed and then nulled object pointers.
0
Thanks Brian
That's correct.. when I solve the *itr issue, I am getting memory dump error.
If I have taken const iterator in first for loop and passing pointer by reference to
trial(p);
Should not it be a compile time error ?
why error : bcz const iterator should not allow modification but passing it by reference does not guarantee no modification