Deference Operator

I can't for the life of me figure out whats going on with the deference operator for mi in the if statements. Does it access the variable's address? Does is it do some sort of decrement? I spent ~2 hrs. last night attempting to Google the viable explanation.

1
2
3
4
5
6
BlockMap::iterator mi = mapBlockIndex.find(blockHash);
    if (mi != mapBlockIndex.end() && (*mi).second) {
        if ((*mi).second->nHeight < chainActive.Height() - 24) {
        return false;
        }
    }


In case more context is needed:
line 623
https://github.com/PIVX-Project/PIVX/blob/master/src/masternode.cpp
Last edited on
operator* is overloaded in iterators to return (a reference to) the object in a collection that iterator is currently referring to. Being a map, the iterators return pairs, where the first element is the key, and the second is the value.

-Albatross
its the object that MI points to. (it being an iterator is important for the bigger picture, but here, it could as well just be a pointer).
its the same as saying mi[0] if mi were an array of that kind of objects (which it is, though it may only have a size of 1).

there is no decrement. its a comparison between the height buried in the mi object chain against the chainactive -24. that is, after subtracting 24 from chainactive, is mi's height still lower?

the first one says
if the pointer is not equal to another pointer (are these the same object, and here, its likely a fancy null check to ensure that mi is actually valid) and mi's second field is not zero (also a null pointer check, using zero == null == nullptr == invalid but zero is false in c++ ideas).

so basically the first one says 'if its valid to do this comparison'
then do the comparison.
Last edited on
Thank you so much!
Topic archived. No new replies allowed.