I'm a novice at writing C++ code, most of my experience is in C# and Java. I have tried a bunch of things but I can't seem to figure out the correct way to structure my statements. Rather than try and explain everything I'm doing wrong I will post example problem code.

std::map<ObjectA, Objectb> dict;

int test(ObjectA arg)
    if(dict[arg] == NULL)
        dict[arg] = new ObjectB;

This doesn't compile, obviously. I know that I need reference and pointer operators in there, I just am unsure where as this is a map object I'm using and I'm also not sure how to check for null entries correctly.

Thanks for any help.

Edited by drspock: n/a

6 Years
Discussion Span
Last Post by Fbody

Try map::find(). You should be able to get an analyzable result from that. Then, if you get a response that means "not found", you can call map::insert() to add the key you were checking for.

The std::map container stores instances of the pair<> data structure (a templatized struct). You may want to read up on that as well.

Edited by Fbody: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.