简体   繁体   中英

Garbage values when C++ Operator Overloading

Im just getting garbage values. And it is wierd the debugger shows the correct values. But its printing weird stuff insted...

this frist part is fine. Essentially, It just takes me to my problem. I have what I need to print inside that h.hashtable[hashIndex] array.

ostream& operator<<(ostream& out, const hashmap& h)
{
        const char *getSymbol = NULL;
        for ( int hashIndex = 0; hashIndex < maxSize; hashIndex++ )
        {   
            getSymbol = h.hashTable[hashIndex].getSymbol();
            if ( getSymbol ) // Find the one I added.
            {
                h.hashTable->display(out);
                    return out << h.hashTable[hashIndex];
            }
        }
        return out;
}

Make sure the stream is set to print in decimal

out << dec << s.m_sharePrice;

( m_sharePrice is a non-pointer type, right?)

Is the values at line:

getSymbol = h.hashTable[hashIndex].getSymbol();

fine, but crap afterwards?

You could be having a case where you have a const char* to something inside an anonymous variable, which gets deleted when the line is done.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM