vendredi 29 mars 2019

Do const class methods prevent assigning variables outside of the class?

I have solved the problem of getting this code to compile by removing the "const". However, why does it seem I cannot assign non-class members in a const class method in this specific situation? It probably is part of the class; though, I do not understand why.

I got my code to compile, but I am confused at this situation.

Below, are some declarations in the class.

using twoDList = multimap<string,string>;
twoDList SomeMultiMap;

This will work when I take off the "const". Or at least compile. Though, here I am just assigning iterators declared only in this function.

bool object::foo(string a, string b) const
{
    pair<Speaker::twoDList::iterator,Speaker::twoDList::iterator> wordRange;
    wordRange = SomeMultiMap.equal_range(a);

    object::twoDList::iterator it = wordRange.first;

    //...
    //...
    //...
}

I expected this function to compile without removing the const, but it does not compile.

Aucun commentaire:

Enregistrer un commentaire