0
I am implementing the Backpack Problem with Dynamic Programming in C++
and chose the deck to build my list. Studying on it, I noticed these two different ways to access a specific position of the list:
//Retorna o item i da lista mydeque
mydeque[i]
mydeque.at(i)
What is the real difference between the two, since at first sight both are identical?
Then the at member function prevents the program from accessing prohibited memory areas?
– Eder Matheus
Yes, in exchange for a small performance penalty, because each access is made a test. And you also have to treat the exception, otherwise your program will be terminated anyway. Using the bracketed operator you are responsible for ensuring that there will be no invalid access.
– C. E. Gesser