C++ operator[] syntax.
- by Lanissum
Just a quick syntax question. I'm writing a map class (for school).
If I define the following operator overload:
template<typename Key, typename Val> class Map {...
Val* operator[](Key k);
What happens when a user writes:
Map<int,int> myMap;
map[10] = 3;
Doing something like that will only overwrite a temporary copy of the [null] pointer at Key k. Is it even possible to do:
map[10] = 3;
printf("%i\n", map[10]);
with the same operator overload?