Prevent direct access to std::map keys

后端 未结 2 898
野的像风
野的像风 2021-01-07 05:01

I would like to wrap a std::map so the client is unaware that I am storing their positive integer keys actually as negative integers. I need to allow iterating

相关标签:
2条回答
  • 2021-01-07 05:11

    I guess you want this:

    if( false == o.empty() )
    {
        do 
        {
            std::cout << "key: " << key << " val: " << value << std::endl;
        }while (o.getNextElement(key, value));
    }
    

    To judge whether it is 'null', before you get elements.

    0 讨论(0)
  • 2021-01-07 05:20
    do 
    {
        std::cout << "key: " << key << " val: " << value << std::endl;
    }while (o.getNextElement(key, value));
    

    So all operations are within the loop like this.

    0 讨论(0)
提交回复
热议问题