Go back to Richel Bilderbeek's homepage.
Go back to Richel Bilderbeek's C++ page.
[C++ Error] MyUnit.cpp(6): E2094 'operator+' not implemented in type '_STL::map<int,double,_STL::less<int>,_STL::allocator<_STL::pair<const int,double> > >' for arguments of type 'int' |
IDE: C++ Builder 6.0
Compiler: Borland BCC32.EXE version 6.0.10.157
Project type: Console Application
Libraries used:
const double getDouble(const std::map<int, double>& myMap, const int i) |
The cause of this compile error is that operator[] is not a const member function. This is because this member function inserts an element to the std::map. It is created to make insertion easy and to never throw. Therefore, the code above will not compile: if myMap does not have the key i, an exception has to be thrown. So, due to this it does not compile. The way to solve the above example is:
#include <map> |
Go back to Richel Bilderbeek's C++ page.
Go back to Richel Bilderbeek's homepage.