I am passing a structure into a subroutine as a const reference. One of the elements of the structure is a map. I am trying to access the map with the .find() function. I am getting an error that says something like "passing 'const MyContainer::MapLessThan' as 'this' argument of 'bool MyContainer::MapLessThan::operator()(const MapType&, const MapType&)' discards qualifiers". The code compiles if I change the subroutine parameter to a non-const. Basically, my code looks like this:
bool subroutineA (const MyStructureType myStructure)
{
MapType::const_iterator iter = myStructure.structMap.find(myKey);
}
well, actually I don't know about map, but const values should be
initialized while created;
I can do that. But, the code is part of a large program. So, I will strip it out and only post the pertinent files. I won't be able to finish until Monday. Thanks.
Here is the code. I trimmed it down to 2 .cc files and 2 .hh files. MyDataLoadWindowCb.cc does not compile. If I remove const from the second parameter of checkForCrossHatching, then it compiles.
//---------------------------------------------------------------------------
// Local Variables
//---------------------------------------------------------------------------
static MyContainer *myContainerInstance;
// The copy constructor and assignment operator are declared
// private and are left unimplemented to ensure that neither is
// automatically generated by the compiler.
MyContainer (const MyContainer &other);
MyContainer& operator=(const MyContainer &other);
MainDataMapType MainDataMap;
public:
bool getMyStatusData
(const int &myIndex,
MyStatusDataType &dataType);
//------------------------------------------------------------------------------
//
// NAME: main
//
// NOTES: Just a place holder.
//
//------------------------------------------------------------------------------
int main ()
{
}
//---------------------------------------------------------------------------
// Local Variables
//---------------------------------------------------------------------------