CPP
cpp
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
/*special thanks to xxx and coder kitten from sl community for their help
https://www.sololearn.com/Discuss/2725807/?ref=app
*/
#include <iostream>
#include <list>
using namespace std;
template<class T>
class mylist : public list<T>
{
public:
T& operator[](size_t index);
};
template<class T>
T& mylist<T>::operator[](size_t index)
{
if (index > this->size() -1)
{
//cout << index << this->size();
throw runtime_error("Index out of bound");
}
auto itr = this->begin();
advance(itr,index);
return *itr;
}
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run