Prevent direct access to std::map keys

后端 未结 2 897
野的像风
野的像风 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.

提交回复
热议问题